Created
March 2, 2022 11:49
-
-
Save ChaseH88/8fee18fd33dae424da65e402afb20700 to your computer and use it in GitHub Desktop.
Fade Out Element - Simply pass a ref into the div. Then onClick, you can utilize this function to fade out the element as it is removed from the DOM.
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
/** | |
* Fade out elements as they're deleted | |
* @param el - the element to focus | |
* @param speed - the speed of the focus | |
* @example | |
const ref = useRef<HTMLDivElement>(null); | |
... | |
fadeOut(ref.current, 500) | |
*/ | |
const fadeOut = (el: HTMLDivElement, speed: number) => { | |
el.style.transition = `opacity ${speed / 1000}s ease`; | |
el.style.opacity = '0'; | |
setTimeout(() => el.parentNode.removeChild(el), speed); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment