Skip to content

Instantly share code, notes, and snippets.

@antimatter15
Created February 27, 2010 22:28
Show Gist options
  • Save antimatter15/317013 to your computer and use it in GitHub Desktop.
Save antimatter15/317013 to your computer and use it in GitHub Desktop.
function fadehover(el){
el.onmouseover = function(){
el.Q = []
fx(el, 500, function(amt, el){
el.style.background = "none";
el.style.backgroundColor = "rgba(0,0,0,"+amt+")"
})
};
el.onmouseout = function(){
el.Q = []
fx(el, 300, function(amt, el){
el.style.background = "none";
el.style.backgroundColor = "rgba(0,0,0,"+(1-amt)+")"
})
}
}
function fx(element, duration, callback){
var amount,
begin = +new Date,
loop;
if(element.R)
return element.Q=(element.Q||[]).concat([arguments]);
element.R = 1;
(loop = function(){ //set the main looper
if(
callback(
(1-Math.cos(
(amount = (new Date-begin)/duration)
*Math.PI))/2,
element
) != 9 //9 terminates execution
&& amount<1 && element.R) setTimeout(loop, 10); else{
!(amount%1)||callback(1,element);
element.R = 0;
element.Q && element.Q.length &&
fx.apply(this, element.Q.shift());
}
})()
}
if(document.querySelectorAll){
var els = document.querySelectorAll(".menu ul li a")
for(var i = 0; i < els.length; i++){
fadehover(els[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment