jQuery 动画错误 = 尝试在清除的范围内运行编译并执行脚本
我希望有人能帮忙解决这个问题。我的页面上的 Firebug 出现了一个奇怪的错误。
我正在使用代码:
$(function () {
var element = $("#finger");
(function(){
element
.animate({ marginLeft: 130 }, 1000)
.animate({ marginLeft: 100 }, 1000 , arguments.callee);
}());
});
这可以很好地为我的“手指”设置动画。
我还有其他代码:
$("SOME-OTHER-DIV").mousedown(function () {
$("#finger").hide();
});
这使得我的“手指”在点击时隐藏。
现在,这一切都工作正常......直到我重新加载页面时出现此错误
“尝试在清除的范围内运行编译并执行脚本”
但是,动画仍然有效,并且鼠标按下也仍然有效仍然有效。
有什么想法吗?这只是 Firefox 中的一个错误吗? 预先非常感谢 Chris
----------更新---------
嗯,也许不是“arguments.callee”导致了问题。我将代码更改为:
$(function () {
i = 0;
while(i < 3){
$("#finger").animate({ marginLeft: 130 }, 1000).animate({ marginLeft: 100 }, 1000);
i++;
}
});
循环 3 次(好吧,不是无限的,但这只是举例),并且在 Firebug 中的页面重新加载时我仍然收到“尝试在已清除的范围内运行编译并运行脚本”错误: -S
I hope someone can help with this. I've got a strange error coming up in Firebug on my page.
I'm using the code:
$(function () {
var element = $("#finger");
(function(){
element
.animate({ marginLeft: 130 }, 1000)
.animate({ marginLeft: 100 }, 1000 , arguments.callee);
}());
});
This works fine to animate my 'finger'.
I also have this other code:
$("SOME-OTHER-DIV").mousedown(function () {
$("#finger").hide();
});
This makes my 'finger' hide when clicked on.
Now, this all works fine.... up until the point when I reload the page whereby I get this error
"attempt to run compile-and-go script on a cleared scope"
Yet, the animation still works, and the mousedown also still works.
Any ideas what's going on here? Is it just a bug in Firefox?
Many thanks in advance
Chris
----------update---------
Hmm, perhaps it's not the "arguments.callee" that's causing the problem. I changed the code to:
$(function () {
i = 0;
while(i < 3){
$("#finger").animate({ marginLeft: 130 }, 1000).animate({ marginLeft: 100 }, 1000);
i++;
}
});
Which loops through 3 times (ok, not infinite, but it's just for example) and I still get the "attempt to run compile-and-go script on a cleared scope" error on page reload in Firebug :-S
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这似乎是FF4的问题。请参阅此和< a href="https://bugzilla.mozilla.org/show_bug.cgi?id=635548" rel="nofollow noreferrer">这个。正如另一个线程所说,尝试清除缓存。
尝试此代码并检查是否仍然收到错误 - demo
如果这不起作用,请尝试使用setInterval 并每 2000 毫秒调用该方法- 演示祝
您的指点业务一切顺利。 ;)
This seems to be an issue with FF4. See this and this. As the other thread says try clearing the cache.
Try this code and check if you still get the error - demo
If that doesn't work try using setInterval and calling the method every 2000 milliseconds - demo
All the best in your finger pointing business. ;)
我认为
arguments.callee
可能是原因。我认为这做了一些并非所有 JS 引擎都完全支持的时髦技巧。I think that
arguments.callee
may be the cause. I think that does some funky trickery that not all JS engines fully support.这是火狐浏览器。如果禁用缓存,则可能不会弹出错误。
在 about:config 中设置:
It's Firefox. If you disable the cache the error probably won't pop up.
In about:config set: