所以我在一个元素上运行两个并发动画,我想在两个动画结束后做一些事情
$("#MyDiv").stop().animate({left: "-=" + 500 + "px"}, 1000);
$("#MyDiv").animate({top: "-=" + 500 + "px"}, 1000,
function() {
//do something here
});
这就是我的方法。我想知道是否有更好的方法,因为第一个动画可能会提前或延迟几毫秒结束。
第二个问题:.stop().animate() 和 .animate() 之间有什么区别吗?如果是,那是什么?
提前致谢!
最佳答案
"because the first animation may end a few milliseconds earlier or later"
不,您已将两个动画设置为 1000 毫秒。
"is there any difference between .stop().animate() and .animate() ? If yes, what is it ?"
是的,如果动画处于事件状态并且调用了 stop(),则第一个动画将停止。
因为您正在为同一个元素设置动画,所以您不需要选择它两次。我建议你这样做:
$("#MyDiv").stop(true).animate({left: "-=" + 500 + "px", top: "-=" + 500 + "px"}, 1000,
function(){
//animation complete
});
如果动画“卡住”,您可以向停止方法添加第二个 bool 值,stop(true, true)
("jumpToEnd")。第一个将清除动画队列。如果不查看更多代码,很难说出您需要什么。
关于javascript - 并发动画结束时的jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14553077/