2011-09-27 126 views
1

我使用这个插件:http://www.spritely.net/ 谁能告诉我为什么变量$ sprite不会重新执行吗?jquery spritefy暂停并重新启动

function animate_header() { 
    var $sprite = $('#header') 
     .sprite({ 
      fps: 30, 
      no_of_frames: 4, 
      // the following are optional: new in version 0.6... 
      start_at_frame: 1, 
      rewind: false, 
      on_last_frame: function(obj) { 
       // you could stop the sprite here with, e.g. 
       obj.spStop(); 
      } 
     }) 
     .active(); 
} 
var init = setInterval("animate_header()", 1000); 

我也试过这样:

function animate_header() { 
    $('#header') 
     .sprite({ 
      fps: 30, 
      no_of_frames: 4, 
      // the following are optional: new in version 0.6... 
      start_at_frame: 1, 
      rewind: false, 
      on_last_frame: function(obj) { 
       // you could stop the sprite here with, e.g. 
       obj.spStop(); 
      } 
     }) 
     .active(); 
} 
var init = setInterval("animate_header()", 1000); 

函数本身执行的每一秒。但精灵不。

+0

什么。主动( )?我不认为它是一种精辟的方法(或者是一个jQuery函数?)。 – orolo

+0

对不起,我明白了。你有没有尝试调用.destroy(),然后重新运行? – orolo

回答

0

我终于实现了这一点。这是我想要的。

function loop() { 

    $('#bird').sprite({fps: 7, no_of_frames: 4, play_frames: 4}); 

      var t = setTimeout(function(){ 
      loop() 
      }, 2000); 
     } 
     loop() 

感谢您的回复。

3

这是为我工作。我先设置选项,然后用spStart函数打开它。

$('#header') 
    .sprite({ 
     fps: 30, 
     no_of_frames: 4, 
     start_at_frame: 1, 
     rewind: false, 
     on_last_frame: function(obj) { 
      // you could stop the sprite here with, e.g. 
      obj.spStop(); 
     } 
    }); 

setInterval ("$('#header').spStart()", 1000); 
0

试着在你的代码的一端与.spStart();更换.active();

貌似obj.spStop()被称为最后一帧上刚刚杀死动画死亡,它需要一个跳跃开始得到它去...... 为我工作:)

1

对于其他人可能发生跌倒在此,使用

.destroy() 

动画似乎跑了几次其他各方面后破门,但破坏的修复吧:)

+0

真的很有用,只是试着解释一下它的用法,这样其他人就可以更容易地使用它了。 –

相关问题