繁体   English   中英

Jquery:如何睡眠或延迟?

[英]Jquery: how to sleep or delay?

我想向上移动对象,延迟 1000 毫秒,然后隐藏它,

我得到了代码:

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

我用 ".animate({"top":"-=0px"},1000)" 来实现延迟,这不好。

我想要:

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

任何的想法?

.delay()怎么样?

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

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

如果您不能使用 Robert Harvey 建议的delay方法,则可以使用setTimeout

例如。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM