In a simple setInterval
setInterval(function() {
// Do something every 9 seconds
}, 9000);
The first action will happen after 9 seconds (t=9s). How to force the loop to perform the first action immediately (t=0)?
I think it is due to the mechanism of setInterval to have Delay - Action - Delay - Action ... loop; instead of Action - Delay - Action - Delay ... loop.
EDIT: My function is indeed a loop as
setInterval(function(){
$('.test').each(function(idx){
var duration = 1000;
$(this).delay(duration*idx);
Some stuff here
});
}, 4000);
Keep it simple. You can use a named function instead of an anonymous function; call it and set an interval for it.
Create a scope if necessary:
Finally, the following works without creating or affecting
x: