I\'ve got an odd little dilemma in this jQuery slideshow plugin that I am building.
It\'s nothing fancy and the code I have written to date is working great however
Instead of timeouts have you tried intervals? Also for it to be recursive, just call the nextSlide() function as its own callback:
var counter = 1;
// animate to the next slide
function nextSlide() {
// increase counter
counter++;
// if counter is greater than the amount of slides, back to the start.
counter = ( counter > slides.length-1 ) ? 0 : counter;
// inner = container to be animated
// in the complete callback restart the timer.
inner.animate(
{
'left': '-' + slides.eq( counter ).position().left
},
{
duration : settings.animationSpeed,
easing : 'easeInOutExpo',
complete : nextSlide()
});
}
Then it's just a matter of starting and stopping an interval:
var slideshow;
function startSlideshow()
{
slideshow = setInterval(nextSlide(),3000);
}
function stopSlideshow()
{
clearInterval(slideshow);
inner.stop();
}
Some browsers (like Chrome) drastically slow down recurring timers when the tab goes inactive and then, when the tab comes active again, they try to "catch up" so that the same number of actual timer events has occurred. All I can think of as a work-around is for you to stop the slideshow entirely when the tab goes inactive and start it again when it comes active.