【问题标题】:Making jQuery animations in queue在队列中制作jQuery动画
【发布时间】:2013-10-04 18:32:28
【问题描述】:

我正在尝试用队列在 div 上做一些动画,但我觉得自己很愚蠢,因为我无法掌握它......我让它在一个 div 上排队动画,但我希望它在几个 div 上完成。

问题: 点击div3后->

Div1 应该变成透明的 (0.5)

完成后

Div2 应该向右移动+50px;

完成后

Div1 应该移到顶部 +50px

完成后

Div2 应该变得透明 (0.5)

我有以下代码,但它不会按预期工作。

    $("#div3").click(function(){
                        $("#div1")
.queue(function(next) {
    $(this).animate({opacity: 0.5}, 
    {duration: 1000, queue: true});
    next();
})
.queue(function(next) {
                $("#div2").animate({right: "+=50"},
    {duration: 2000})
    next(); 

})

 .queue(function(next) {
                 $(this).animate({top: "+=50"},
    {duration: 2000})
    next(); 


})
  .queue(function(next) {
                 $("#div2").animate({opacity: 0.5}, 
    {duration:4000, queue: true});

    next(); 
                  });           

                          });

有人可以帮我吗?提前谢谢你

【问题讨论】:

    标签: javascript jquery html css


    【解决方案1】:

    你可以试试下面的代码

    $("#div3").click(function(){
       $("#div1").animate({opacity: 0.5},{duration: 1000}, function() {
            $("#div2").animate({right: "+=50"},{duration: 2000}, function(){
                $("#div1").animate({top: "+=50"},{duration: 2000}, function(){
                    $("#div2").animate({opacity: 0.5}, {duration:4000});
                });
            });
        });
    });
    

    【讨论】:

    • 感谢您(超级)快速的回答,但代码只执行第一个动画......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-10
    • 1970-01-01
    相关资源
    最近更新 更多