Created
January 31, 2014 09:26
-
-
Save jjmu15/8728940 to your computer and use it in GitHub Desktop.
fadeIn vanilla JS
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
function fadeIn(el) { | |
var opacity = 0 | |
el.style.opacity = 0 | |
el.style.filter = '' | |
var last = +new Date | |
var tick = function() { | |
opacity += (new Date - last) / 400 | |
el.style.opacity = opacity | |
el.style.filter = 'alpha(opacity=' + (100 * opacity)|0 + ')' | |
last = +new Date | |
if (opacity < 1) | |
(window.requestAnimationFrame && requestAnimationFrame(tick)) || setTimeout(tick, 16) | |
} | |
tick() | |
} | |
fadeIn(el) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment