How to block the thread javascript runs on? [duplicate]
Possible Duplicate:
Sleep in Javascript
How can I block the execution for random amount of milliseconds to say do the fadeIn
on several divs to pop them up on the screen one after the other, in sequential order, but appearing gracefully kinda like google top menu comes back little after the search box is rendered?
var numDivs = 5;
var fadeDelay = 500;
for (i=1;i<=numDivs;i++) {
setTimeout(function() {$("#div_"+i).fadeIn(fadeDelay)}, fadeDelay*i);
}
You can pass a function and a delay to setTimeout
, but you can't force a thread to "sleep" in JavaScript.
精彩评论