【问题标题】:I want to change the height of an element twice using one jquery animation but I can't. How to do it?我想使用一个 jquery 动画两次更改元素的高度,但我不能。怎么做?
【发布时间】:2013-04-01 20:44:09
【问题描述】:

我想使用一个 jquery 动画两次更改元素的高度,但我不能。怎么做?

我正在使用代码:

$("#animate").click(function() {
$("#content")
    .animate({"height": "200px"},{"queue": true, "duration": 500})
    .animate({"width": "250px"}, {"queue": true, "duration": 500});
    .animate({"height": "100px"},{"queue": true, "duration": 500})
});

什么都没有发生.. 但是,如果我删除任何一个高度动画,它就可以正常工作。 提前谢谢..

【问题讨论】:

  • 可以看看stackoverflow.com/questions/11065626/…>
  • 试试这个L: $("#content") .animate({"height": "200px"},{"queue": true, "duration": 500}) .animate({"宽度”:“250px”},{“队列”:真,“持续时间”:500}).animate({“高度”:“100px”},{“队列”:真,“持续时间”:500})} );
  • 在宽度动画语句之后使用';'关闭它jQuery 不知道应该将第三个动画语句应用于哪个元素。要么删除';'或指定第三个动画语句的元素。

标签: jquery animation


【解决方案1】:

您的代码中存在语法错误,您可能不得不将第二个高度动画推迟到第一个完成后

$("#animate").click(function() {
$("#content").animate({
            "height" : "200px"
        }, {
            "queue" : true,
            "duration" : 500,
            complete : function() {
                $(this).animate({
                            "height" : "100px"
                        }, {
                            "queue" : true,
                            "duration" : 500
                        })
            }
        }).animate({
            "width" : "250px"
        }, {
            "queue" : true,
            "duration" : 500
        });
});

【讨论】:

    【解决方案2】:

    把它串起来:

    $("#content").animate({"height": 200}, 500, function(){
       $(this).animate({"width" : 250}, 500, function(){
          $(this).animate({"height" : 100}, 500)
       })
    });
    

    【讨论】:

      【解决方案3】:

      您需要删除;:

      .animate({"width": "250px"}, {"queue": true, "duration": 500}); // <-- Here
      

      【讨论】:

      猜你喜欢
      • 2021-12-08
      • 2011-12-14
      • 1970-01-01
      • 2019-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-14
      • 1970-01-01
      相关资源
      最近更新 更多