Skip to content

Instantly share code, notes, and snippets.

@Voskresenskyi-Serhii
Forked from alirezas/fade.js
Created September 1, 2020 09:16
Show Gist options
  • Select an option

  • Save Voskresenskyi-Serhii/ef36147a3760313a8a5eb9c897e9c738 to your computer and use it in GitHub Desktop.

Select an option

Save Voskresenskyi-Serhii/ef36147a3760313a8a5eb9c897e9c738 to your computer and use it in GitHub Desktop.
fadeIn & fadeOut in vanilla js
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);
}
})();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment