Created
May 20, 2011 01:46
-
-
Save gnarf/982197 to your computer and use it in GitHub Desktop.
Idea for Animate
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
// 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