[英]How can I make this a better recursive animated jQuery script?
这个想法是为一个云div设置动画,让它永久地水平来回动画。 这很有效,但不幸的是我认为它容易出现内存泄漏和UI滞后。 任何建议都会很感激,谢谢。
function animateCloud() {
$('#cloud').animate({ right: '+=500' }, { duration: 35000, easing: "linear", queue: true });
animateOpposite();
}
function animateOpposite() {
$('#cloud').animate({ right: '-=500' }, { duration: 35000, easing: "linear", queue: true });
animateCloud();
}
$(document).ready(function() {
animateCloud();
});
我认为您的代码根本不会泄漏内存,但您可以更短地创建调用。
function animateCloud() {
$('#cloud').animate({ right: '+=500' }, { duration: 35000, easing: "linear" })
.animate({ right: '-=500' }, { duration: 35000, easing: "linear", complete: animateCloud });
}
http://api.jquery.com/animate/
使用可选的回调参数。 动画结束后,jquery会调用你的函数。 完美的时间来动画其他方向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.