0

How can I trigger a slideUp(); with a delayed start, but which doesn't force the rest of the code to wait until it has finished before progressing.

eg: A button is pressed and 1 second later a box disappears, but jquery is still working during that one second.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Patrick Beardmore
  • 1,026
  • 1
  • 11
  • 35
  • possible duplicate of [delay JQuery effects](http://stackoverflow.com/questions/251204/delay-jquery-effects) – Shog9 Mar 13 '11 at 19:15

3 Answers3

2

See this previous SO question on exactly the same topic.

setTimeout(function() { /* code to run */ }, delay_time_in_milliseconds);
Community
  • 1
  • 1
Amber
  • 507,862
  • 82
  • 626
  • 550
2

You can use Javascript's setTimeout() function for this.

E.g.

setTimeout(function() { $('#someid').slideUp(); }, 1000); // 1000ms = 1sec.
Shog9
  • 156,901
  • 35
  • 231
  • 235
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1

You can use jQuery's .delay() method to queue animations.

$('#el').delay(1000).slideUp();

If you want to delay something else, then use JavaScript's built-in setTimeout() function.

setTimeout(function() {
    // code to be executed
}, 1000);

Note that you need to specify the delay in milliseconds in both cases. 1000 ms = 1 s.

alexia
  • 14,440
  • 8
  • 42
  • 52