hi i have a slideshow with forward and previous buttons.
I have this code inside a function , i post it as i think it is the relevant part.
function next(){
if(that.current>3){
that.current=0;
}
images[0].style.zIndex=1;
images[3].style.zIndex=1;
images[2].style.zIndex=1;
images[1].style.zIndex=1;
switch(that.current){
case 0:
if(that.repeat==0){
images[0].style.visibility="visible";
images[0].style.zIndex=6;
showInfo(info[0],0);
}else{
images[0].style.zIndex=5;
images[3].style.zIndex=6;
fadeOut(images[3],0,images[0]);
showInfo(info[0],0);
}
break;
case 1:
images[1].style.zIndex=5;
images[0].style.zIndex=6;
fadeOut(images[0],0,images[1]);
showInfo(info[1],0);
break;
case 2:
images[2].style.zIndex=5;
images[1].style.zIndex=6;
fadeOut(images[1],0,images[2]);
showInfo(info[2],0);
break;
case 3:
images[3].style.zIndex=5;
images[2].style.zIndex=6;
fadeOut(images[2],0,images[3]);
showInfo(info[3],0);
break;
}
that.repeat=1;
}
function previous(){
if(that.current<0){
that.current=3;
}
images[0].style.zIndex=1;
images[3].style.zIndex=1;
images[2].style.zIndex=1;
images[1].style.zIndex=1;
switch(that.current){
case 0:
images[0].style.zIndex=6;
images[3].style.zIndex=5;
fadeOut(images[0],0,images[3]);
showInfo(info[3],0);
break;
case 1:
images[1].style.zIndex=6;
images[0].style.zIndex=5;
fadeOut(images[1],0,images[0]);
showInfo(info[0],0);
break;
case 2:
images[2].style.zIndex=6;
images[1].style.zIndex=5;
fadeOut(images[2],0,images[1]);
showInfo(info[1],0);
break;
case 3:
images[3].style.zIndex=6;
images[2].style.zIndex=5;
fadeOut(images[3],0,images[2]);
showInfo(info[2],0);
break;
}
that.repeat=1;
}
next();
that.loop=setInterval(function(){that.current++;next();},5000);
var linkNext=document.getElementById("next");
linkNext.onclick=function(){clearInterval(that.loop);that.current++;next();}
var linkPrev=document.getElementById("prev");
linkPrev.onclick=function(){that.previous=1;clearInterval(that.loop);that.current--;previous();}
You can see the working script here http://web-in-a-box.co.cc/#
The problems is that when first clicked previous decrements
that.current
by 2, not by 1 as internded , for the first click. Next clicks are ok in the same function, but when you click next ,after you’ve clicked previous , next also increments by 2 .