mirror of
https://github.com/animate-css/animate.css.git
synced 2024-11-13 07:41:08 +01:00
Suggesting using addEventListener once option in docs
Adding `{once : true}` to `node.addEventListener` causes the event trigger to be removed after first use. This built-in method cleans up the requirement to remove event within event handler.
This commit is contained in:
parent
4e4dfb6af5
commit
e22d9c8689
1 changed files with 2 additions and 4 deletions
|
@ -37,14 +37,12 @@ const animateCSS = (element, animation, prefix = 'animate__') =>
|
|||
node.classList.add(`${prefix}animated`, animationName);
|
||||
|
||||
// When the animation ends, we clean the classes and resolve the Promise
|
||||
function handleAnimationEnd() {
|
||||
handleAnimationEnd = () => {
|
||||
node.classList.remove(`${prefix}animated`, animationName);
|
||||
node.removeEventListener('animationend', handleAnimationEnd);
|
||||
|
||||
resolve('Animation ended');
|
||||
}
|
||||
|
||||
node.addEventListener('animationend', handleAnimationEnd);
|
||||
node.addEventListener('animationend', handleAnimationEnd, {once : true});
|
||||
});
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in a new issue