Small optimization to step() method...

Small optimization to step() method...


Since I've been looking at the animation code a lot today, I noticed a quick
optimization that save a few processing cycles and reduce the code.
The current code has the following check to see if an animation is done:
var done = true;
for ( var i in this.options.curAnim )
if ( this.options.curAnim[i] !== true )
done = false;
However, if "done == false" the next line that's actually executed is return
false. You can just remove the done variable all together and just return
false after that check. This simplifies the code to:
// Each step of an animation
step: function(gotoEnd){
var t = (new Date()).getTime();
if ( gotoEnd || t > this.options.duration + this.startTime ) {
this.now = this.end;
this.pos = this.state = 1;
this.update();
this.options.curAnim[ this.prop ] = true;
for ( var i in this.options.curAnim )
if ( this.options.curAnim[i] !== true )
return false
if ( this.options.display != null ) {
// Reset the overflow
this.elem.style.overflow = this.options.overflow;

// Reset the display
this.elem.style.display = this.options.display;
if ( jQuery.css(this.elem, "display") == "none" )
this.elem.style.display = "block";
}
// Hide the element if the "hide" operation was done
if ( this.options.hide )
this.elem.style.display = "none";
// Reset the properties, if the item has been hidden or shown
if ( this.options.hide || this.options.show )
for ( var p in this.options.curAnim )
jQuery.attr(this.elem.style, p, this.options.orig[p]);
// If a callback was provided, execute it
if ( jQuery.isFunction( this.options.complete ) )
// Execute the complete function
this.options.complete.apply( this.elem );
return false;
} else {
var n = t - this.startTime;
this.state = n / this.options.duration;
// Perform the easing function, defaults to swing
this.pos = jQuery.easing[this.options.easing || (jQuery.easing.swing ?
"swing" : "linear")](this.state, n, 0, 1, this.options.duration);
this.now = this.start + ((this.end - this.start) * this.pos);
// Perform the next step of the animation
this.update();
}
return true;
}
Obviously just a small optimization...
-Dan