jquery spritefy pause and restart
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 exec开发者_如何学Goutes every second. But the sprite doesn't.
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 );
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 :)
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 :)
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.
精彩评论