Skip to content Skip to sidebar Skip to footer

Settimeout/loop... Still Confused

So I've been all over this since yesterday afternoon. I have done various iterations of the basic code I have trying to get the result I want (I want dropping markers in order ever

Solution 1:

If you don't want all your results at once, you need to give different times, because the loop is executed instantly and all the timeout are computed from the time of this execution :

setTimeout(function() { 

}, 1000*i);

And to avoid the problem of all iterations using the same value of i, protect it in a closure using

for (i = 0; i < location.length; i++) {
   (function(i){
       setTimeout(function() { 

       }, 1000*i);
   })(i);
}

Post a Comment for "Settimeout/loop... Still Confused"