[英]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()
怎么样?
$("#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.