jquery spritefy 暂停和重新启动

发布于 2024-12-06 23:09:14 字数 1168 浏览 0 评论 0原文

我正在使用这个插件: http://www.spritely.net/ 谁能告诉我为什么变量 $sprite 不重新执行?

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

函数本身每秒执行一次。但精灵却没有。

I'm useing this plugin: http://www.spritely.net/
Can anyone tell me why the variable $sprite doesn't re-execute?

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

I also tried this:

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

The function itself executes every second. But the sprite doesn't.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

滥情哥ㄟ 2024-12-13 23:09:14

这对我有用。我首先设置选项,然后使用 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 );

This is what worked for me. I set the options first, then I looped it with the spStart function.

$('#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 );
§普罗旺斯的薰衣草 2024-12-13 23:09:14

对于其他可能偶然发现这一点的人,请使用

.destroy()

动画似乎在以其他方式运行几次后中断,但 destroy 修复了它:)

For anyone else that might happen to stumble on this, use

.destroy()

The animation seems to break after running a few times every other way, but destroy fixes it :)

栩栩如生 2024-12-13 23:09:14

尝试在代码末尾将 .active(); 替换为 .spStart();

看起来像在最后一帧调用的 obj.spStop() 只会杀死动画,并且需要一个跳跃启动才能使其继续...
为我工作:)

try replacing .active(); with .spStart(); at the end of your code.

Looks like obj.spStop() that is called on last frame just kills animation dead and it needs a jump start to get it going...
Worked for me :)

白芷 2024-12-13 23:09:14

我最终这样做了。哪个如我所愿。

function loop() {

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

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

不过还是感谢您的回复。

I ended up doing this. Wich worked as I wanted.

function loop() {

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

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

Thanks for any replies though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文