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
|
@ -37,14 +37,12 @@ const animateCSS = (element, animation, prefix = 'animate__') =>
|
||||||
node.classList.add(`${prefix}animated`, animationName);
|
node.classList.add(`${prefix}animated`, animationName);
|
||||||
|
|
||||||
// When the animation ends, we clean the classes and resolve the Promise
|
// When the animation ends, we clean the classes and resolve the Promise
|
||||||
function handleAnimationEnd() {
|
handleAnimationEnd = () => {
|
||||||
node.classList.remove(`${prefix}animated`, animationName);
|
node.classList.remove(`${prefix}animated`, animationName);
|
||||||
node.removeEventListener('animationend', handleAnimationEnd);
|
|
||||||
|
|
||||||
resolve('Animation ended');
|
resolve('Animation ended');
|
||||||
}
|
}
|
||||||
|
|
||||||
node.addEventListener('animationend', handleAnimationEnd);
|
node.addEventListener('animationend', handleAnimationEnd, {once : true});
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue