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 (which has to be loaded first!)
10 // We override the animation for all of these color styles
11 $.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'],
13 $.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)
28 function getColor(elem, attr) {
32 color = $.curCSS(elem, attr);
34 // Keep going until we find an element that has color, or we hit the body
35 if ( color != '' && color != 'transparent' || $.nodeName(elem, 'body') )
38 attr = 'backgroundColor';
39 } while ( elem = elem.parentNode );
41 return $.colorUtil.getRGB(color);