Why does setInterval run very fast after some time? I used the code
below for a background slideshow on my site. I also use the fullpage preloader plugin.
function slideSwitch() {
var $active = $('#slideshow IMG.active');
if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
var $next = $active.next().length ? $active.next() : $('#slideshow IMG:first');
$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}
$(function() {
setInterval( "slideSwitch()", 9999);
});
//use fullpage preloader
QueryLoader.init();
I want to repeat the animation every 9999 milliseconds. But after some time (5-7 minutes), the animation seems to repeat every 1000 milliseconds.
the javascript function setInterval() returns a handle
that you can clear whenever you want with clearInterval
So you’d have to clean your interval after some time, for that you want to use setTimeout