窗口加载上的 jQuery 动画无限循环?
我需要有人帮助让下面的代码正常工作。我已经让它工作了,这样当用户将鼠标悬停在图像上时,它会向上移动,然后在失去焦点时向下移动,但现在我希望它在无限循环的窗口加载上运行。
$(document).ready(function(){
$(window).load(function(){
$('.navImage').animate({top:'-=13'}, 700)
}, function(){
$('.navImage').animate({top:'+=13'}, 700);
});
});
目前,它仅向上移动 13 像素,而不是向下移动 13 像素,并且显然动画当前不循环。我需要使用某种回调吗?
任何帮助都会很棒,谢谢。
[编辑] 删除了高度:切换,并不意味着包括它。
I need a hand making this code below working. I've had it working so that when the user hovers over the image it animates up, then down when losing focus, but now I want it to run on window load on an infinite loop.
$(document).ready(function(){
$(window).load(function(){
$('.navImage').animate({top:'-=13'}, 700)
}, function(){
$('.navImage').animate({top:'+=13'}, 700);
});
});
At the moment it's only animating 13pixels up, not down, and obviously the animation doesn't currently loop. Do I need to use some sort of callback?
Any help would be great, thanks.
[EDIT] Removed the height:toggle, didn't mean to include that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
=== UPDATE 1 ===
另请参阅我的 jsfiddle。
=== 更新 2 ===
现在它们以随机延迟开始:
另请参阅我的 jsfiddle 2。
=== 更新 3 ===
在这个 jsfiddle 中,附加了随机速度:jsfiddle 3。
Try this:
=== UPDATE 1 ===
Also see my jsfiddle.
=== UPDATE 2 ===
Now they start with random delay:
Also see my jsfiddle 2.
=== Update 3 ===
And in this jsfiddle additional with random speed: jsfiddle 3.
作为旁注,如果只有一个,您应该用 ID 替换该
navImage
类。As a sidenote, you should replace that
navImage
class with an ID instead, if there's only one of them.