This is what i am trying to accomplish: when the last slide is reached fadeOut last slide and then fadeIn first slide, and then clearInterval (everything works with th
After clear an interval you need to start it again with setInterval()
.
It would be better to make function for your setInterval()
var intervalID = null;
function intervalManager(flag, animate, time) {
if(flag)
intervalID = setInterval(animate, time);
else
clearInterval(intervalID);
}
Here flag
is a boolean
variable with value true/ false
. true
will execute setInterval()
and false
will clearInterval()
;
Now you can use above function as you need.
For example:
intervalManager(true, animate, 300); // for setInterval
intervalManager(false); // for clearInterval