Created
February 13, 2017 10:54
-
-
Save alirezas/c4f9f43e9fe1abba9a4824dd6fc60a55 to your computer and use it in GitHub Desktop.
fadeIn & fadeOut in 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 fadeOut(el){ | |
el.style.opacity = 1; | |
(function fade() { | |
if ((el.style.opacity -= .1) < 0) { | |
el.style.display = "none"; | |
} else { | |
requestAnimationFrame(fade); | |
} | |
})(); | |
}; | |
function fadeIn(el, display){ | |
el.style.opacity = 0; | |
el.style.display = display || "block"; | |
(function fade() { | |
var val = parseFloat(el.style.opacity); | |
if (!((val += .1) > 1)) { | |
el.style.opacity = val; | |
requestAnimationFrame(fade); | |
} | |
})(); | |
}; |
Thanks!
Those functions are great. But i need promisified versions.How could you return promise from those functions?
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks.