Skip to content

Instantly share code, notes, and snippets.

@1yzo
Created October 24, 2018 10:58
Show Gist options
  • Save 1yzo/251068f0d2852f71b778d05271f3fbe9 to your computer and use it in GitHub Desktop.
Save 1yzo/251068f0d2852f71b778d05271f3fbe9 to your computer and use it in GitHub Desktop.
Transition opacity
const fadeIn = (element, duration) => {
element.style.display = 'flex';
(function increment(value = 0) {
element.style.opacity = String(value);
if (element.style.opacity !== '1') {
setTimeout(() => {
increment(value + 0.1);
}, duration / 10);
}
})();
};
const fadeOut = (element, duration) => {
(function decrement() {
(element.style.opacity -= 0.1) < 0 ? element.style.display = 'none' : setTimeout(() => {
decrement();
}, duration / 10);
})();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment