2

I want to change the height of an element twice using one jquery animation but I can't. How to do it?

I am using the code:

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

And nothing is happenning.. But if I remove any one of the height animation it works fine. Thanks in advance..

bipen
  • 36,319
  • 9
  • 49
  • 62
  • can have a look at – Darshan Apr 10 '13 at 06:32
  • try thisL: $("#content") .animate({"height": "200px"},{"queue": true, "duration": 500}) .animate({"width": "250px"}, {"queue": true, "duration": 500}) .animate({"height": "100px"},{"queue": true, "duration": 500}) }); – Amyth Apr 10 '13 at 06:33
  • 1
    after the width animate statement you close it using ';' jQuery does not know to which element it should apply the third animate statement. Eitherremove the ';' or specify the element for the third animate statement. – Amyth Apr 10 '13 at 06:34

3 Answers3

4

You need to remove the ;:

.animate({"width": "250px"}, {"queue": true, "duration": 500}); // <-- Here
Eli
  • 14,779
  • 5
  • 59
  • 77
1

There is a syntax error in your code as well as you may have to postpone the second height animation till the first one is completed

$("#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
        });
});
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
1

make it in a chain:

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