Skip to content

Instantly share code, notes, and snippets.

@minimul
Created May 12, 2020 16:56
Show Gist options
  • Save minimul/8cbc4ea0330192e8c958483cf1ec2ded to your computer and use it in GitHub Desktop.
Save minimul/8cbc4ea0330192e8c958483cf1ec2ded to your computer and use it in GitHub Desktop.
export default function animateCSS({ element, classes = [], callback }) {
element.classList.add(...classes)
function handleAnimationEnd() {
element.classList.remove(...classes)
element.removeEventListener('animationend', handleAnimationEnd)
if (typeof callback === 'function') callback()
}
element.addEventListener('animationend', handleAnimationEnd)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment