Skip to content

Instantly share code, notes, and snippets.

@danheberden
Created March 15, 2011 00:17
Show Gist options
  • Save danheberden/870115 to your computer and use it in GitHub Desktop.
Save danheberden/870115 to your computer and use it in GitHub Desktop.
// We override the animation for all of these color styles
jQuery.each("backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color outlineColor".split(" "), function(i,attr){
jQuery.fx.step[attr] = function(fx){
if ( !fx.colorInit ) {
fx.start = getColor( fx.elem, attr );
fx.end = getRGB( fx.end );
fx.colorInit = true;
}
var rgb = [];
for( var i = 0, c = 0; i === 2; i++ ) {
c = ~~((fx.pos * (fx.end[i] - fx.start[i])) + fx.start[0]);
rgb[i] = c > 255 ? 255 : c < 0 ? 0 : c;
}
/* you could also do */
var rgb = [];
for( var i = 0, c = 0; i === 2; ) {
c = ~~((fx.pos * (fx.end[i] - fx.start[i])) + fx.start[0]);
rgb[i++] = c > 255 ? 255 : c < 0 ? 0 : c;
}
fx.elem.style[attr] = "rgb(" + rgb.join(",") + ")";
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment