Reputation: 544
How do I include a Javascript function in the middle of the animate queue? For example I would like to call alert()
in between these two jQuery functions to animate the height property:
$('#divContainer').animate({ height: "200px" }, 'slow').alert('alert goes here').animate({ height: "50px" }, 'slow');
Upvotes: 0
Views: 83
Reputation: 37739
You can do the following:
$('#divContainer').animate({ height: "200px" }, 'slow', function() { alert('alert goes here'); }).animate({ height: "50px" }, 'slow');
The documentation for animate specifies you can pass a callback.
Upvotes: 0
Reputation: 816840
That's what .queue()
[docs] is for:
$('#divContainer')
.animate({ height: "200px" }, 'slow')
.queue(function(next){
alert('alert goes here');
next();
})
.animate({ height: "50px" }, 'slow');
Upvotes: 4