Skip to content

Instantly share code, notes, and snippets.

@gnarf
Created May 20, 2011 01:46
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 gnarf/982197 to your computer and use it in GitHub Desktop.
Save gnarf/982197 to your computer and use it in GitHub Desktop.
Idea for Animate
// helper function
function animate( props, opts ) {
var el = this,
anim = $.Deferred(),
propTimers = $.map( props, function( property, value ) {
// $.Timer is a deferred(progress?? jQuery.Callbacks if they make it into 1.7)
// object that is inserted into the jQuery.timers array that also
// picks up some of the properties/calcs from jQuery.fx -- "step" function
// animation data, etc...
var prop = $.Timer( el, property, duration );
// do some animation stuffs here!!!
return prop;
}).get();
$.when.apply( $, propTimers )
.done( function() {
anim.resolveWith( el );
}).fail( function() {
anim.rejectWith( el );
});
// when "anim" is rejected, cancel all property animations
anim.fail( function() {
$.each( propTimers, function() {
this.reject();
// abort the timer if anything fails??
// this doesn't happen in old code, but it could be done....
});
});
return anim;
}
$.fn.animate = function( props, duration, easing, callback ) {
// oversimplified:
var opts = jQuery.speed(duration,easing,callback);
this.queue(opts.queue, function( next ) {
var el = $(this),
anim = animate( props, opts );
anim.then( next, function( clearQueue, gotoEnd ) {
if ( clearQueue ) {
el.queue(opts.queue).clear();
} else {
el.dequeue();
}
// gotoEnd would be handled in the $.Timer() reject
});
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment