Created
October 24, 2018 10:58
-
-
Save 1yzo/251068f0d2852f71b778d05271f3fbe9 to your computer and use it in GitHub Desktop.
Transition opacity
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
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