我有两个函数,tick 和 tock。它们使 4 个数字先向一个方向旋转,然后再向另一个方向旋转。每个数字都可以以不同的速度缓解。
我可以调用这两个函数,但我不能让第二个(tock)等到所有数字都在第一个(tick)中移动完毕。
我已经查看了使用回调的其他类似问题,但我似乎无法用我的示例来实现这一点。我要么在第一个函数完成之前结束第二个函数,要么就像下面的代码一样,只使用第一个函数。
谢谢
$(document).ready(function(){
var complete = 0;
tick('', function(){tock();});
function tick(a){
$('#col1 img')
.delay('1000')
.animate({bottom:'-=80px'},5000,'easeInOutSine');
complete++;
$('#col2 img')
.delay('1000')
.animate({bottom:'+=720px'},1000,'easeInOutSine');
complete++;
$('#col3 img')
.delay('1000')
.animate({bottom:'+=560px'},500,'easeInOutSine');
complete++;
$('#col4 img')
.delay('1000')
.animate({bottom:'-=240px'},2000,'easeInOutSine');
complete++;
}
function tock(){
$('#col1 img')
.delay('1000')
.animate({bottom:'+=80px'},2000,'easeInOutSine');
$('#col2 img')
.delay('1000')
.animate({bottom:'-=720px'},2000,'easeInOutSine');
$('#col3 img')
.delay('1000')
.animate({bottom:'-=560px'},2000,'easeInOutSine');
$('#col4 img')
.delay('1000')
.animate({bottom:'+=240px'},2000,'easeInOutSine');
}
});