Jquery 动画回调函数

Jquery callback function on animate

我想出了如何为这种类型做一个回调函数jquery动画方法

$("#div1").animate({top: "-=100"}, 2000, function(){alert("hi")});

但我似乎无法弄清楚如何使用这个 animate() 函数制作一个简单的警报回调函数。

$('#div1').animate({top: "-800"}, {duration: 3000}).animate({left: "-700"}, 
{duration: 3000, queue: false});

试试这个

$('#div1')
.animate({top: "-800"}, {duration: 3000})
.animate({left: "-700"}, {duration: 3000, queue: false, complete: function() {console.log('done');}});

在这种情况下,回调函数必须是选项对象的一部分,例如 complete: function() { // code here }