jQuery动画回调问题
function thumb_wheel() {
$("#slider .nivo-controlNav img").animate({left: '-600px'}, 14000, function(){
$(this).css({left:'0px'}, function(){
thumb_wheel();
});
});
};
基本上,一旦动画完成,我希望它将“left”重置为 0px,并再次调用自身。我尝试过使用 setInterval 等不同的方式对其进行格式化...检查了 Google、Stack 和 #jQuery...无论我尝试什么,当我添加重置时它似乎都会“挂起”。有什么想法吗?
function thumb_wheel() {
$("#slider .nivo-controlNav img").animate({left: '-600px'}, 14000, function(){
$(this).css({left:'0px'}, function(){
thumb_wheel();
});
});
};
Basically, once the animation finishes, I would like it to reset "left" to 0px, and call itself again. I've tried formatting it different ways, using setInterval, etc... Checked Google, Stack, and #jQuery... and no matter what I try, it seems to 'hang' when I add the reset. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在此 jsfiddle 中看到一个可行的解决方案:
http://jsfiddle.net/GjemU/
您的代码中存在一些语法错误,并且您尝试在
.css
上使用不存在的回调You can see a working solution in this jsfiddle:
http://jsfiddle.net/GjemU/
You had some syntax errors in your code as well as you tried to use a non-existing callback on
.css
回调在不同的作用域中被调用,因此
this
变量指向的对象与您想象的不同。解决方案是使用闭包:
the callback is being called in a different scope, so the
this
variable points to a different object than you think.The solution is to a use closure: