Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery How to slideUp with delay?

I am using the following jQuery. A div box slides up, and then after 5 seconds, fades out. Is there a way to achieve this as it takes a long time for the box to appear.

$(document).ready(function() {
  $("#load_limit").slideUp(500); //have tried "fast" also
  $("#load_limit").delay(5000);
  $("#load_limit").slideDown(500);
});
like image 495
TheBlackBenzKid Avatar asked Feb 15 '26 13:02

TheBlackBenzKid


2 Answers

You can delay in the callback function:

$(document).ready(function() {
  $("#load_limit").slideUp(500, function() {
     $("#load_limit").delay(5000).slideDown(500);
  }); 
});

or you can just simplified it:

$(document).ready(function() {
  $("#load_limit").slideUp(500)
                  .delay(5000)
                  .slideDown(500);
});

Code: http://jsfiddle.net/xjEy5/2/

like image 57
Samich Avatar answered Feb 18 '26 02:02

Samich


Find the div, wait for n seconds and then take n milliseconds transition time to slide up.

$("#div").delay(5000).slideUp(1000);
like image 44
anonym Avatar answered Feb 18 '26 04:02

anonym