2014-09-22 50 views
8

我想实现一个jQuery的动画回调方法的进步或台阶,jQuery的动画设置回调抛出错误

但在任何情况下,我发现了以下错误:

NS_ERROR_IN_PROGRESS: Component returned failure code: 0x804b000f (NS_ERROR_IN_PROGRESS) [nsICacheEntry.dataSize] 

我搜索了很多,但无法在上下文中找到任何内容,我有点卡在这里,请提出可能导致此错误的原因?

在拨弄我尝试步骤和进步及其在那里工作,但没有能够得到它在我的代码工作,我只是希望,有一些一个面临的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 
    }) 
); 
+0

你在生产环境中使用jQuery的哪个版本? – GuyT 2014-09-30 11:48:01

+0

根据Firefox的源代码中的错误消息和一些窥探,这是一个缓存项目的问题,尚未完成加载/正在写入。发布代码中没有任何内容表明您正在使用可能尚未加载的任何资源,因此我认为我们很难再帮助您,除非我们看到更多的代码。 – Falle1234 2014-09-30 12:32:01

+0

这是一个iOS应用程序吗? – SnareChops 2014-10-01 04:28:19

回答

3

你必须要对一些语义错误在这里。我要重新发布代码,格式为便于阅读:

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 clearing method想要做什么,但是动画完成后你想要发生的任何事情都应该在step方法旁边添加的complete方法中。

第二:$.proxy()需要具有您希望它作为第二个参数运行的上下文,而不是其他“完整”功能。

所以这里是一个稍作修改的例子。你可以自己试试this fiddle

var vtop = 100; 

$('div') 
    .stop(true, true) 
    .animate(
     { 
      top: vtop, 
      width: 0, 
      opacity : 0 
     }, 
     { 
      duration: 2000, 
      step: function() { 
       console.log('I am called'); 
      }, 
      complete: function() { 
       alert('complete');// some further actions after animation completes 
      } 
     } 
    ); 
+0

上面的代码是正在运行的代码,所以我无法删除$ .proxy(),$ .proxy()只是为了清除由动画引起的所有样式的目标,如将其重置为其原始宽度,顶部等。这就是执行正常,只有改变我在这里使用步骤或进度回调。 – 2014-09-24 09:05:28

+0

好的。如果它有效,那么一定要按原样使用它。无论如何,您提到的错误代码看起来不像JavaScript错误。你确定你的问题不在其他地方吗? – 2014-09-24 09:33:16

+0

事情是我不得不操纵动画效果作为目标动画,这就是为什么我需要使用步骤或进度,但只要我编写步骤或进度回调方法它会引发我这个错误,甚至它dint捕获回调方法块, – 2014-09-24 09:35:22

1

你可以使用朱利安·夏皮罗的Velocity.js,该动画是(有争议的)比jQuery和CSS(read this更多)

更快它可以让你使用回调,如:

  • 开始
  • 进度
  • 完成

,如:

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 

注意,你只需要更换.animate().velocity()

JSFIDDLE