Jquery 如何防止循环动画暂停
(咖啡休息时间) 具有以下特征:Jquery 如何防止循环动画暂停,jquery,animation,Jquery,Animation,(咖啡休息时间) 具有以下特征: $('.cloud').each(function(){ var cloud = $(this); function move(){ mL = Math.round(Math.random()*60); mT = Math.round(Math.random()*60); cloud.animate({left: mL, top: mT },2000); }
$('.cloud').each(function(){
var cloud = $(this);
function move(){
mL = Math.round(Math.random()*60);
mT = Math.round(Math.random()*60);
cloud.animate({left: mL, top: mT },2000);
}
move();
setInterval(function() {
move();
}, 2000);
});
正如您在方框中看到的那样,暂停2秒后的任何移动。然后他们继续循环。有什么方法可以让它们在没有暂停/重启感觉的情况下滚动?非常感谢:)不。好的,现在我看到计时器了,它一文不值,但您的示例结果与我上面发布的相同。云在2秒后停止移动,重新开始。同样的事情。Maight be stop不是正确的词,所以我将其改为“暂停”。你可以在动画中使用线性缓和,这样它在过渡的开始和结束时不会加速和减速-请参阅:谢谢你的时间比利!就是这样!:)度量是jquery动画的一个重要特性。你可以下载有更多广告的插件,bounce特别有用
$('.cloud').each(function(){
var cloud = $(this);
function move(){
mL = Math.round(Math.random()*60);
mT = Math.round(Math.random()*60);
// set callback upon complete animation
// set easing to linear to prevent acceleration and deceleration of animation
cloud.animate({left: mL, top: mT },2000,'linear',move);
}
move();
// get rid of timer
});