Skip to content

Instantly share code, notes, and snippets.

@octan3
Created February 1, 2013 13:01
Show Gist options
  • Save octan3/4691177 to your computer and use it in GitHub Desktop.
Save octan3/4691177 to your computer and use it in GitHub Desktop.
Animate the backgroundColor-opacity-value.
$.fx.step.backgroundColor = function(fx) {
if (!fx._init) {
// parse RGBA-Color
var col = /\((\d+,\s*\d+,\s*\d+),\s*([\d\.]+)\s*\)/.exec($.css(fx.elem, 'backgroundColor'));
// set correct start-value
fx.start = parseFloat(col[2]);
// remember background-color
fx._baseColor = col[1];
// run only once
fx._init = true;
}
// do the job
fx.elem.style.backgroundColor = 'rgba(' + fx._baseColor + ', ' + fx.now + ')';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment