JQuery: how to sleep or linger?

I want to move the object, hold for 1000 ms, then hide it,

I get the code:

$("#test").animate({"top":"-=80px"},1500) .animate({"top":"-=0px"},1000) .animate({"opacity":"0"},500); 

i use ".animate ({" top ":" - = 0px "}, 1000)" to implement the delay, this is not good.

I want to:

 $("#test").animate({"top":"-=80px"},1500) .sleep(1000) .animate({"opacity":"0"},500); 

any idea?

+60
javascript jquery
May 30 '10 at 19:30
source share
2 answers

What about .delay() ?

http://api.jquery.com/delay/

 $("#test").animate({"top":"-=80px"},1500) .delay(1000) .animate({"opacity":"0"},500); 
+96
May 30 '10 at 19:33
source share

If you cannot use the delay method, as suggested by Robert Harvey, you can use setTimeout .

Eg.

 setTimeout(function() {$("#test").animate({"top":"-=80px"})} , 1500); // delays 1.5 sec setTimeout(function() {$("#test").animate({"opacity":"0"})} , 1500 + 1000); // delays 1 sec after the previous one 
+56
May 30 '10 at 20:42
source share



All Articles