Skip to content

Instantly share code, notes, and snippets.

@dumconstantin
Created April 18, 2011 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dumconstantin/925586 to your computer and use it in GitHub Desktop.
Save dumconstantin/925586 to your computer and use it in GitHub Desktop.
var anim = {
// Temporary cue of animations
anims : [],
// Stored cue of animations for looping
store: [],
// Register a temporary animation
register : function(obj, anim, dur, out) {
this.anims.push([obj, anim, dur, out]);
},
// Start the animations. When an animation is done it gets
// erased from the temporary cue.
start : function() {
if(this.anims.length != 0) {
var cur = this.anims.shift();
var that = this;
var once = true;
$(cur[0]).animate(cur[1], cur[2], function() {
if(once) {
setTimeout(function() { that.start() }, cur[3]);
once = false;
}
});
} else {
this.refresh();
}
},
// Comes back to the original form and starts looping.
refresh : function() {
this.anims = this.store.slice(0);
this.start();
},
// Save the current cue.
save : function() {
this.store = this.anims.slice(0);
}
}
/*
** Usage:
anim.register('#slide-1', {opacity:1, width:100, height:200}, 2000, 200);
anim.register('#slide-2', {opacity:1, width:10, height:20}, 2000, 200);
anim.save(); // this is for looping
anim.start(); // start animation
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment