Skip to content

Instantly share code, notes, and snippets.

@jjmu15
Created January 31, 2014 09:26
Show Gist options
  • Save jjmu15/8728940 to your computer and use it in GitHub Desktop.
Save jjmu15/8728940 to your computer and use it in GitHub Desktop.
fadeIn vanilla JS
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