如何在动画队列中包含javascript函数?

时间:2011-06-28 21:19:03

标签: jquery

如何在动画队列中间包含Javascript函数?例如,我想在这两个jQuery函数之间调用alert()来设置height属性的动画:

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

2 个答案:

答案 0 :(得分:4)

这就是.queue() [docs]的用途:

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

答案 1 :(得分:0)

您可以执行以下操作:

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

animate的documentation指定您可以传递回调。