2 * jQuery Color Animations
3 * Copyright 2007 John Resig
4 * Released under the MIT and GPL licenses.
6 * - 2011-01-05: Modified by Krinkle to use the jQuery.colorUtil plugin (needs to be loaded first)
11 // We override the animation for all of these color styles
12 jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
13 jQuery.fx.step[attr] = function(fx){
14 if ( fx.state == 0 ) {
15 fx.start = getColor( fx.elem, attr );
16 fx.end = $.colorUtil.getRGB( fx.end );
19 fx.elem.style[attr] = "rgb(" + [
20 Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
21 Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
22 Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
27 function getColor(elem, attr) {
31 color = jQuery.curCSS(elem, attr);
33 // Keep going until we find an element that has color, or we hit the body
34 if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
37 attr = "backgroundColor";
38 } while ( elem = elem.parentNode );
40 return $.colorUtil.getRGB(color);