【问题标题】:Jquery animation sequence with $.when()带有 $.when() 的 Jquery 动画序列
【发布时间】:2014-04-02 09:50:37
【问题描述】:

我有结构

$('.qwe').click(function(){

            $.when(
                $('#q1').animate({top: 100}, 1000),
                $('#q2').animate({top: 200}, 500)
            ).then(function () {
                $('#q3').fadeOut();
            });

        });

它可以按我的需要工作,但我想在其他功能中取出动画:

    function asd(){
        $('#q1').animate({top: 100}, 1000);
        $('#q2').animate({top: 200}, 500);
    }
    $('.qwe').click(function(){

        $.when(asd()).then(function () {
                $('#q3').fadeOut();
            }
        );

    });

为什么动画同时执行?

【问题讨论】:

    标签: jquery callback jquery-animate


    【解决方案1】:

    试试这个:在 jquery 中使用回调

     $('.qwe').click(function(){
    
            $('#q1').animate({top: 100}, 1000 , function() {
    
                  $('#q2').animate({top: 200}, 500, function() { 
    
                            $('#q3').fadeOut();
                   });
             });
    
    
      });
    

    【讨论】:

    • 这个方法不适合,因为我需要在单独的函数中取出动画
    猜你喜欢
    • 2011-06-30
    • 2013-08-08
    • 2015-11-19
    • 2011-05-11
    • 2012-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-22
    相关资源
    最近更新 更多