Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery动画设置回调抛出错误_Javascript_Jquery_Css_Jquery Animate - Fatal编程技术网

Javascript jQuery动画设置回调抛出错误

Javascript jQuery动画设置回调抛出错误,javascript,jquery,css,jquery-animate,Javascript,Jquery,Css,Jquery Animate,我想实现一个jQuery动画回调方法progress或step 但无论哪种情况,我都会得到以下错误: NS_ERROR_IN_PROGRESS: Component returned failure code: 0x804b000f (NS_ERROR_IN_PROGRESS) [nsICacheEntry.dataSize] 我搜索了很多,但在上下文中找不到任何内容,我有点被困在这里,请建议是什么导致了这个错误 在fiddle中,我尝试了step and progress及其在那里的工作,但

我想实现一个jQuery动画回调方法progress或step

但无论哪种情况,我都会得到以下错误:

NS_ERROR_IN_PROGRESS: Component returned failure code: 0x804b000f (NS_ERROR_IN_PROGRESS) [nsICacheEntry.dataSize]
我搜索了很多,但在上下文中找不到任何内容,我有点被困在这里,请建议是什么导致了这个错误

在fiddle中,我尝试了step and progress及其在那里的工作,但无法在我的代码中工作,我只是看看,有人在jquery动画中遇到过这样的错误吗?

示例代码是:

    this.taskHandle.find('img').stop(true, true).animate({
        //todo//
        top: vtop, // this.taskHandle.outerHeight(),
        //'top': 0 - $('.target.upper').height(),
        width: 0,
        opacity: 0
    }, {
        duration: 2000,
        step: function(){
            console.log('I am called');
        }
    },

    $.proxy(function() {
        // some css clearing method
    }, {
        // some further actions after animation completes
    })
);

这里有一些语义错误。我将重新发布您的代码,以便于阅读:

this.taskHandle.find('img')
    .stop(true, true)
    .animate(
        {
            //todo//
            top:  vtop , // this.taskHandle.outerHeight(),
            //'top' : 0 - $('.target.upper').height(),
            width : 0,
            opacity : 0
        },
        {
            duration:2000,
            step: function() {
                console.log('I am called');
            }
        },
        $.proxy(
            function() {
                // some css clearing method
            },
            {
                // some further actions after animation completes
            }
        )
    );
首先:
animate()
不接受3个参数(至少不接受这3个参数)。我不确定您想用
css清除方法做什么,但是动画完成后不想发生的事情应该在
complete
方法中,该方法添加在
步骤
方法旁边

其次:
$.proxy()
需要有一个上下文,您希望它作为第二个参数运行,而不是其他一些“完整”函数

下面是一个稍微修改过的示例,它是有效的。你可以自己试一试


您可以使用Julian Shapiro的,该动画比jQuery和CSS(更多信息)更快(值得商榷)

它允许您使用回调,例如:

  • 开始
  • 进展
  • 完整的
比如:

var vtop = 100;
jQuery(document).ready(function ($) {
    $('div').find("img").velocity({
        top: vtop,
        width: 0,
        opacity: 0
    }, {
        duration: 2000,
        begin: function (elements) {
            console.log('begin');
        },
        progress: function (elements, percentComplete, timeRemaining, timeStart) {
            $("#log").html("<p>Progress: " + (percentComplete * 100) + "% - " + timeRemaining + "ms remaining!</p>");
        },
        complete: function (elements) {
            // some further actions after animation completes
            console.log('completed');
            $.proxy( ... ); // some css clearing method
        }
    });
}); // ready
var vtop=100;
jQuery(文档).ready(函数($){
$('div').find(“img”).velocity({
顶部:vtop,
宽度:0,
不透明度:0
}, {
期限:2000年,
开始:功能(元素){
log('begin');
},
进度:功能(元素、完成百分比、剩余时间、timeStart){
$(“#log”).html(进度:+(完成百分比*100)+“%-”+剩余时间+“剩余毫秒!”

); }, 完成:功能(元素){ //动画完成后的一些进一步操作 console.log('completed'); $.proxy(…);//一些css清除方法 } }); }); // 准备好的
请注意只需将
.animate()
替换为
.velocity()


请参见

上面的代码是正在运行的代码,因此我无法删除$.proxy(),$.proxy()只是为了清除由动画引起的所有样式的目标,如将其重置为其原始宽度、顶部等。这执行得很好,只是我在此处所做的更改,以使用步骤或进度回调。确定。如果它有效,那么无论如何,按原样使用它。无论如何,你在问题中提到的错误代码在我看来不像JavaScript错误。你确定你的问题不在其他地方吗?问题是我必须操作动画效果作为目标动画这就是为什么我需要使用step或progress,但一旦我编写step或progress回调方法,它就会抛出这个错误,甚至无法捕获回调方法块,您是否可以尝试删除
animate()
$.proxy()
-部分)的第三个参数,仅用于测试。现在,您正在使用允许的参数的某种混合,我认为它只在以前起作用,因为您的options对象上唯一的属性是
duration
,当您添加
step
时,它会中断。您得到的错误是“NS\u error…”可能是由弹出窗口阻止程序引起的,我猜您正在firefox上测试代码:)您在生产环境中使用哪个jQuery版本?根据错误消息和firefox源代码中的一些窥探,这是一个缓存项的问题,该缓存项尚未完成加载/编写。发布的代码中没有任何内容表明您正在使用任何可能未加载的资源,因此我认为我们将很难进一步帮助您,除非我们看到更多的代码。这是一个iOS应用程序吗?不是.net应用程序
var vtop = 100;
jQuery(document).ready(function ($) {
    $('div').find("img").velocity({
        top: vtop,
        width: 0,
        opacity: 0
    }, {
        duration: 2000,
        begin: function (elements) {
            console.log('begin');
        },
        progress: function (elements, percentComplete, timeRemaining, timeStart) {
            $("#log").html("<p>Progress: " + (percentComplete * 100) + "% - " + timeRemaining + "ms remaining!</p>");
        },
        complete: function (elements) {
            // some further actions after animation completes
            console.log('completed');
            $.proxy( ... ); // some css clearing method
        }
    });
}); // ready