[jQuery] animate function with color fading
jQuery.fn._animate = function(prop, speed, callback) {
return this.queue(function(){
var i = 0;
for ( var p in prop ) {
var e = new jQuery.fx( this, jQuery.speed(speed,callback,i++), p );
if (jQuery.matchRGB(prop[p])) {
new function(){
var pn = p;
var ps = jQuery.matchRGB(jQuery.curCSS(e.el, p));
var pe = jQuery.matchRGB(prop[p]);
e.a = function(){
var v = [];
for (var i=0; i<ps.length; i++) {
v[i] = parseInt(ps[i] + (pe[i] - ps[i]) * this.now);
}
jQuery.attr(this.el.style, p, "rgb("+ v.join() +")");
};
};
e.custom(0, 1);
} else if (prop[p].constructor == Number) {
e.custom( e.cur(), prop[p] );
} else {
e[ prop[p] ]( prop );
}
}
});
};
jQuery.matchRGB = function(v){
var r = new RegExp(
"rgb\\(\\s*(\\d+%?)\\s*,\\s*(\\d+%?)\\s*,\\s*(\\d+%?)\\s*\\)"+
"|#([\\dA-F]{2})([\\dA-F]{2})([\\dA-F]{2})"+
"|#([\\dA-F])([\\dA-F])([\\dA-F])"
);
var c = v.match(r);
// color parsing
if (c) {
for (var i=0; i<3; i++)
switch (c[7] && 7 || c[4] && 4 || 1) {
case 1: c[i] = c[i+1] * (c[i+1].indexOf('%') > 0 ? 2.55 : 1); break;
case 7: c[i+4] = c[i+7] + c[i+7];
case 4: c[i] = parseInt(c[i+4], 16);
}
c.length = 3;
}
return c;
};
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/