如何在动画队列中间包含Javascript函数?例如,我想在这两个jQuery函数之间调用alert()
来设置height属性的动画:
$('#divContainer').animate({ height: "200px" }, 'slow').alert('alert goes here').animate({ height: "50px" }, 'slow');
答案 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指定您可以传递回调。