开发者

How to block the thread javascript runs on? [duplicate]

开发者 https://www.devze.com 2023-02-10 00:25 出处:网络
This question already has answers here: 开发者_JS百科 Closed 11 years ago. Possible Duplicate: Sleep in Javascript
This question already has answers here: 开发者_JS百科 Closed 11 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消