0

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?

Community
  • 1
  • 1
dexter
  • 7,063
  • 9
  • 54
  • 71
  • possible duplicate of [Sleep in Javascript](http://stackoverflow.com/questions/758688/sleep-in-javascript) and about a million others. – user229044 Feb 13 '11 at 08:54

2 Answers2

1

You can pass a function and a delay to setTimeout, but you can't force a thread to "sleep" in JavaScript.

user229044
  • 232,980
  • 40
  • 330
  • 338
1
var numDivs = 5;
var fadeDelay = 500;
for (i=1;i<=numDivs;i++) {
   setTimeout(function() {$("#div_"+i).fadeIn(fadeDelay)}, fadeDelay*i);
}
Joe Hanink
  • 4,767
  • 4
  • 19
  • 21