【问题标题】:jQuery wait till all page animations are donejQuery等待所有页面动画完成
【发布时间】:2016-02-22 23:15:55
【问题描述】:

我知道如何等到动画完成

$('#element').animate(speed,function(){
//code here
});

并带有多个元素

$('#element1, #element2').promise().done(function(){
//code here
});

但是我如何等到页面上的所有元素完成动画处理?我宁愿不只是把我正在等待的每一个元素都放进去。

【问题讨论】:

    标签: jquery animation promise


    【解决方案1】:

    要选择当前正在动画的所有内容,只需执行$(":animated") http://api.jquery.com/animated-selector/

    结合你已经拥有的,它就是

    $(":animated").promise().done(function() {
        //code here
    });
    

    【讨论】:

      【解决方案2】:

      Jeremy T 给出的答案效果很好 - 尽管基于他链接的 jquery 站点上的 cmets (http://api.jquery.com/animated-selector/),但将一个类添加到页面上可能动画的每个元素将是一个更快的解决方案,然后使用

      选择它们
          $('.animationclass').filter(':animated').promise().done(function() {
      //Your function
      });
      

      【讨论】:

        猜你喜欢
        • 2012-08-23
        • 2014-01-21
        • 2017-03-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多