jQuery Animation error =尝试在已清除的范围上运行compile-and-go脚本
我希望有人可以帮忙解决这个问题。 我的页面上的Firebug出现了一个奇怪的错误。
我正在使用代码:
$(function () { var element = $("#finger"); (function(){ element .animate({ marginLeft: 130 }, 1000) .animate({ marginLeft: 100 }, 1000 , arguments.callee); }()); });
这可以很好地动画我的’手指’。
我还有其他代码:
$("SOME-OTHER-DIV").mousedown(function () { $("#finger").hide(); });
点击时,这会让我的“手指”隐藏起来。
现在,这一切都很好….直到我重新加载页面,我得到这个错误
“尝试在已清除的范围内运行编译和运行脚本”
然而,动画仍然有效,而mousedown仍然有效。
有什么想法在这里发生了什么? 它只是Firefox中的一个错误吗? 非常感谢克里斯
———- ———更新
嗯,也许不是造成问题的“arguments.callee”。 我将代码更改为:
$(function () { i = 0; while(i < 3){ $("#finger").animate({ marginLeft: 130 }, 1000).animate({ marginLeft: 100 }, 1000); i++; } });
哪个循环通过3次(好的,不是无限的,但它只是例如)并且我仍然在Firebug中重新加载页面上的“尝试在清除的范围上运行编译和运行脚本”错误:-S
这似乎是FF4的一个问题。 看到这个和这个 。 正如另一个线程所说的尝试清除缓存。
尝试此代码并检查是否仍然出现错误 – 演示
$(function() { animateFinger(); }); $("#abc").mousedown(function() { $("#finger").toggle("display"); }); function animateFinger() { $("#finger").animate({ marginLeft: 130 }, 1000).animate({ marginLeft: 0 }, 1000, animateFinger); }
如果这不起作用,请尝试使用setInterval并每2000毫秒调用一次方法 – 演示
$(function() { animateFinger(); setInterval(animateFinger, 2000); // You can also try function(){setTimeout(animateFinger, 0)} as a callback method instead of setInterval }); $("#abc").mousedown(function() { $("#finger").toggle("display"); }); function animateFinger() { $("#finger").animate({ marginLeft: 130 }, 1000).animate({ marginLeft: 0 }, 1000); }
在您的指点业务中一切顺利。 ;)
我认为arguments.callee
可能是原因。 我认为这并不是所有JS引擎都完全支持的一些时髦技巧。
这是Firefox。 如果禁用缓存,则可能不会弹出错误。
在about:config set:
network.http.use-cache = false