/    Sign up×
Community /Pin to ProfileBookmark

slideshow – disable previous/next button when on the first/last image

I have a working slideshow script that provides the following:
– Pulls images from image folder
– Renders caption text for each image
– Renders image count
– Contains Next and Previous image buttons with rollover effects

What I still need this script to do:
– Prevent slideshow from looping
– Disable the previous button when on the first image; disable the next button when on the last image

Coming from the Flash environment, my JavaScript web skills are lacking. Can someone give me a hand to resolve the stop the loop, show disabled button on first/last image issue?

thanks.

[CODE]
<script type=”text/javascript”>
<!–

function newImage(arg) {
if (document.images) {
rslt = new Image();
rslt.src = arg;
return rslt;
}
}

function changeImages() {
if (document.images && (preloadFlag == true)) {
for (var i=0; i<changeImages.arguments.length; i+=2) {
document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
}
}
}

var preloadFlag = false;
function preloadImages() {
if (document.images) {
demo_left_btn_01_over = newImage(“../images/demo_left_btn_01-over.gif”);
demo_left_btn_01_down = newImage(“../images/demo_left_btn_01-down.gif”);
demo_left_btn_01_disabled = newImage(“../images/demo_left_btn_01-disabled.gif”);
demo_rt_btn_01_over = newImage(“../images/demo_rt_btn_01-over.gif”);
demo_rt_btn_01_down = newImage(“../images/demo_rt_btn_01-down.gif”);
demo_rt_btn_01_disabled = newImage(“../images/demo_rt_btn_01-disabled.gif”);
preloadFlag = true;
}
}

function ShowState_disabled() {
changeImages(‘demo_left_btn_01’, ‘demo_left_btn_01_disabled’);
}

function ShowState_disabled() {
changeImages(‘demo_rt_btn_01’, ‘demo_rt_btn_01_disabled’);
}

// –>
</script>
<!– End Preload Script –>

<!– slideshow script –>
<script language=”JavaScript” type=”text/javascript”>
theimage = new Array();

// The dimensions of ALL the images should be the same or some of them may look stretched or reduced in Netscape 4.
// Format: theimage[…]=[image URL, link URL, name/description]
theimage[0]=[“../images/demo_imgs/image_01.gif”, “”, “Caption for image 01”];
theimage[1]=[“../images/demo_imgs/image_02.gif”, “”, “Caption for image 02”];
theimage[2]=[“../images/demo_imgs/image_03.gif”, “”, “Caption for image 03”];
theimage[3]=[“../images/demo_imgs/image_04.gif”, “”, “Caption for image 04”];
theimage[4]=[“../images/demo_imgs/image_05.gif”, “”, “Caption for image 05”];

///// Plugin variables

dotrans=0; // if value = 1 then there are transitions played in IE

//key that holds where in the array currently are
i=0;

//###########################################
window.onload=function(){

//preload images into browser
preloadSlide();

//set the first slide
SetSlide(0);

}

//###########################################
function SetSlide(num) {
//too big
i=num%theimage.length;
//too small
if(i<0)i=theimage.length-1;

//switch the image
if(document.all&&!window.opera&&dotrans==1)eval(‘document.images.imgslide.filters.’+transtype+’.Apply()’)
document.images.imgslide.src=theimage[i][0];
if(document.all&&!window.opera&&dotrans==1)eval(‘document.images.imgslide.filters.’+transtype+’.Play()’)

//if they want name of current slide
document.getElementById(‘captionbox’).innerHTML=theimage[i][2];

//if they want current slide number and total
document.getElementById(‘imagecount’).innerHTML= ” “+(i+1)+” / “+theimage.length;

}

//###########################################
function preloadSlide() {
for(k=0;k<theimage.length;k++) {
theimage[k][0]=new Image().src=theimage[k][0];
}
}

</script>
[/CODE]

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@frog01authorAug 09.2006 — Thanks! This is the interaction I needed. However, I am having a problem implementing the image description text and number of images counter from my original script.

This link shows the Description: text and the Number of Pictures: n of total that I need to implement into the script that you provided.

http://www.dynamicdrive.com/dynamicindex14/interslide.htm

Thanks again.
Copy linkTweet thisAlerts:
@bg3boyNov 26.2006 — Hi, I'm brand new here. After reading multiple posts, I really like the script the script that konithomimo refers to the best. I'm trying to use it for the site I'm working on, but the problem is that I want to use text links instead of buttons. I'm not sure how to change the code correctly in order to use text links (I'm definitely not a programmer).

If somebody can point me in the right direction I would really appreciate it.

Thanks in advance.
Copy linkTweet thisAlerts:
@konithomimoNov 26.2006 — Here it my old code redone for links, and changed to disable all of the neccessary buttons instead of just the previous and next buttons:

&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;

var photos=new Array()

/*Change the below variables to reference your own images. You may have as many images in the slider as you wish*/
photos[0]="finish1.jpg"
photos[1]="finish2.jpg"
photos[2]="finish3.jpg"

function showPic(t)
{var s = document.getElementById('imageplaceholder');
var sp =s.src.split('/');
var i, j;

//Assign all links to variables, and make them all usable
var p = document.getElementById('prev');
var n = document.getElementById('nex');
var f = document.getElementById('fir');
var l = document.getElementById('las');
p.disabled = false;
n.disabled = false;
f.disabled = false;
l.disabled = false;

//Option 1 - Go to first slide
if(t==0)
{s.src=photos[0];
p.disabled = true;
f.disabled = true;
return true;}

//Option 2 - Go to last slide
else if(t==2)
{s.src=photos[photos.length-1];
n.disabled = true;
l.disabled = true;
return true;
}

//Else we want to move back/forwards by 1
for(i=0;i&lt;photos.length;i++)
{j=i+t;

if(sp[sp.length-1] == photos[i])
{
s.src = photos[j];

//This means we want to move to the first slide, so disable the first and previous links
if(j==0)
{
p.disabled = true;
f.disabled= true;
}

//This means we want to move to the last slide, so disable the last and next links
if(j==photos.length-1)
{
n.disabled = true;
l.disabled = true;
}

return true;
}
}
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form&gt;
&lt;a href="#" onclick="showPic(-1)" id="prev" disabled&gt;Previous&lt;/a&gt;
&lt;a href="#" onclick="showPic(1)" id="nex" &gt;Next&lt;/a&gt;
&lt;a href="#" onclick="showPic(0)" id="fir" disabled&gt;First&lt;/a&gt;
&lt;a href="#" onclick="showPic(2)" id="las"&gt;Last&lt;/a&gt;
&lt;br&gt;
&lt;img src="finish1.jpg" id="imageplaceholder"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@bg3boyNov 27.2006 — Awesome. I'll give it a try and let you know if I have questions.
×

Success!

Help @frog01 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...