Created
April 18, 2011 15:48
-
-
Save dumconstantin/925586 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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