I’m trying to loop through divs with a delay in between. It works okay the first couple of times through. But then it just keeps getting faster. I can’t figure out what I’m doing. Help me stackoverflow, you’re my only hope.
showSlides();
function showSlides() {
$('.mySlides:not(:first)').hide();
$.map($('.mySlides'),function(el){
myTimeout=setTimeout(function(){
console.log(el);
$(el).siblings().fadeOut(1000);
$(el).fadeIn(1000);
if($(el).is(':last-child')) { clearTimeout(myTimeout); showSlides(); }
},7000);
});
}
3
Answers
No need for each, map or interval, just use delay and jQuery will loop for you
You are setting timeout for all the slides together almost the same instant. A quick fix is to set in advance the timing in a 7 seconds intervals.
Here is another take on it: