Skip to main content

jQuery setTimeout issue



I have a simple function that animates a bunch of images by crossfading them. A simple banner rotation. I set up the function so that calling animateSlideshow("play") it should set the timeout and start animating and by calling animateSlideshow("stop") it should stop.





When I call stop, however, the animation happens one more time. What is the cause for this one extra animation and how can I deal with it?







function animateSlideshow(action){



if(action === "play"){

$(activeSlide).data('animateSlideshow',

setTimeout(function(){



if( $(actvImg).index() === total - 1 ){

$(actvImg).fadeOut(animationSpeed).removeClass("actvImg").siblings().eq(0).fadeIn(animationSpeed).addClass("actvImg");

}else{

$(actvImg).fadeOut(animationSpeed).removeClass("actvImg").next().fadeIn(animationSpeed).addClass("actvImg");

}



actvImg = $(".rightSlides li.active .rightSlide > li.actvImg");

actvImgIndx = $(actvImg).index();

updateBreadcrumbs();

animateSlideshow("play")



}, animationTimeout)

);

}else{

clearTimeout($(activeSlide).data('animateSlideshow'));

};



};




Comments

Popular posts from this blog

Wildcards in a hosts file

I want to setup my local development machine so that any requests for *.local are redirected to localhost . The idea is that as I develop multiple sites, I can just add vhosts to Apache called site1.local , site2.local etc, and have them all resolve to localhost , while Apache serves a different site accordingly.