Koe*_*err 60 javascript jquery
我想向上移动物体,延迟1000ms,然后隐藏它,
我得到的代码:
$("#test").animate({"top":"-=80px"},1500)
.animate({"top":"-=0px"},1000)
.animate({"opacity":"0"},500);
Run Code Online (Sandbox Code Playgroud)
我用".animate({"top":" - = 0px"},1000)"来实现延迟,这不好.
我想要:
$("#test").animate({"top":"-=80px"},1500)
.sleep(1000)
.animate({"opacity":"0"},500);
Run Code Online (Sandbox Code Playgroud)
任何的想法?
Rob*_*vey 95
怎么样.delay()
?
$("#test").animate({"top":"-=80px"},1500)
.delay(1000)
.animate({"opacity":"0"},500);
Run Code Online (Sandbox Code Playgroud)
mqc*_*hen 56
如果您不能delay
像Robert Harvey建议的那样使用该方法,则可以使用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
Run Code Online (Sandbox Code Playgroud)