jQuery动画错误=尝试在已清除的范围内运行编译脚本 [英] jQuery Animation error = attempt to run compile-and-go script on a cleared scope

查看:127
本文介绍了jQuery动画错误=尝试在已清除的范围内运行编译脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人可以提供帮助.我的页面上的Firebug中出现了一个奇怪的错误.

I hope someone can help with this. I've got a strange error coming up in Firebug on my page.

我正在使用代码:

$(function () {
var element = $("#finger");
(function(){
    element
        .animate({ marginLeft: 130 }, 1000)
        .animate({ marginLeft: 100 },   1000 , arguments.callee);
}());
});

这可以使我的手指"动起来.

This works fine to animate my 'finger'.

我还有其他代码:

$("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.

有什么想法吗?这只是Firefox中的错误吗? 提前谢谢了 克里斯

Any ideas what's going on here? Is it just a bug in Firefox? Many thanks in advance Chris

----------更新---------

----------update---------

导致问题的原因可能不是"arguments.callee".我将代码更改为:

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++;
}
});

这会循环3次(好的,不是无限的,但这只是举例),在Firebug中重新加载页面时,我仍然收到试图在清除范围内运行编译脚本"的错误:-S

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

推荐答案

这似乎与FF4有关.参见.正如另一个线程所说,尝试清除缓存.

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

$(function() {
    animateFinger();
});

$("#abc").mousedown(function() {
    $("#finger").toggle("display");
});

function animateFinger() {
    $("#finger").animate({
        marginLeft: 130
    }, 1000).animate({
        marginLeft: 0
    }, 1000, animateFinger);
}


如果这不起作用,请尝试使用 setInterval 并每2000年调用一次该方法毫秒-演示


If that doesn't work try using setInterval and calling the method every 2000 milliseconds - demo

$(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);
}

在您的指点业务中一切顺利. ;)

All the best in your finger pointing business. ;)

这篇关于jQuery动画错误=尝试在已清除的范围内运行编译脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆