Created
August 3, 2013 01:30
-
-
Save anonymous/6144689 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#fade { | |
width: 100px; | |
height: 100px; | |
border-radius: 50%; | |
border: none; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<button type="button" id='fade' onMouseOver="fadeEffect.init('fade', 0, 90)" onMouseOut="fadeEffect.init('fade', 0)"><p>Hello!</p></button> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fadeEffect=function(){ | |
return{ | |
init:function(id, flag, target){ | |
this.elem = document.getElementById(id); | |
clearInterval(this.elem.si); | |
this.target = target ? target : flag ? 100 : 0; | |
this.flag = flag || -1; | |
this.alpha = this.elem.style.opacity ? parseFloat(this.elem.style.opacity) * 100 : 0; | |
this.elem.si = setInterval(function(){fadeEffect.tween();}, 20); | |
}, | |
tween:function(){ | |
if(this.alpha == this.target){ | |
clearInterval(this.elem.si); | |
}else{ | |
var value = Math.round(this.alpha + ((this.target - this.alpha) * 0.05)) + (1 * this.flag); | |
this.elem.style.opacity = value / 100; | |
this.elem.style.filter = 'alpha(opacity=' + value + ')'; | |
this.alpha = value; | |
} | |
} | |
}; | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment