2013-04-10 91 views
2

我想改变一个元素的高度使用一个jQuery动画两次,但我不能。怎么做?我想使用一个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}) 
}); 

,并没有什么happenning .. 但如果我删除了高度的动画中的任何一个,它工作正常。 在此先感谢..

+0

可以看看一t Darshan 2013-04-10 06:32:18

+0

试试这个:$(“#content”) .animate({“height”:“200px”},{ ({“width”:“250px”},{“queue”:true,“duration”:500}) .animate({“height”:true,“duration”:500}) .animate “100px”},{“queue”:true,“duration”:500}) }); – Amyth 2013-04-10 06:33:12

+1

在使用';'关闭宽动画语句之后jQuery不知道应该应用第三个动画语句的元素。要么删除';'或者为第三个动画语句指定元素。 – Amyth 2013-04-10 06:34:55

回答

0

。在你的代码中的语法错误,以及你可能不得不推迟第二高度动画,直到第一个完成

$("#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 
     }); 
}); 
4

您需要删除;

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

非常感谢,这些愚蠢的错误让我发疯...... – user2264734 2013-04-10 06:42:31

+0

@ user2264734很高兴帮助!如果它解决了您的问题,请接受答案:http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Eli 2013-04-10 07:39:05

0

使其在链:

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