开发者

How do include a javascript function in the animate queue?

How do I include a Javascript functi开发者_开发技巧on 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');


That's what .queue() [docs] is for:

$('#divContainer')
  .animate({ height: "200px" }, 'slow')
  .queue(function(next){
      alert('alert goes here');
      next();
  })
  .animate({ height: "50px" }, 'slow');


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜