jQuery 等待所有页面动画完成
我知道如何等待动画完成
$('#element').animate(speed,function(){
//code here
});
并使用多个元素
$('#element1, #element2').promise().done(function(){
//code here
});
,但是如何等待页面上的所有元素都完成动画处理?我宁愿不只是把我正在等待的每一个元素都放进去。
I know how to wait till an animation is done with
$('#element').animate(speed,function(){
//code here
});
and with multiple elements with
$('#element1, #element2').promise().done(function(){
//code here
});
but how do I wait till all of the elements on the page are done animating? I would much rather not just put in every element that I'm waiting for in there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要选择当前正在动画的所有内容,只需执行
$(":animated")
http://api.jquery.com/animated-selector/
将其与您已有的内容相结合在那里,它只是
To select everything that's being animated currently, just do
$(":animated")
http://api.jquery.com/animated-selector/
Combining that with what you already have there, it'd just be
Jeremy T 给出的答案效果很好 - 尽管基于他链接的 jquery 网站上的评论(http://api.jquery. com/animated-selector/),向页面上可能有动画的每个元素添加一个类,然后使用选择它们将是一个更快的解决方案
The answer given by Jeremy T works fine - although based on the comments on the jquery site he linked (http://api.jquery.com/animated-selector/), it would be a faster solution to add a class to each element on the page that may be animated, and then select them using