|
@@ -83,5 +83,23 @@ export default {
|
|
|
y: posRaw.y * scale,
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+ animateCSS(element, animation, prefix = 'animate__') {
|
|
|
+ // We create a Promise and return it
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ const animationName = `${prefix}${animation}`
|
|
|
+ const node = typeof element === 'string' ? document.querySelector(element) : element
|
|
|
+
|
|
|
+ node.classList.add(`${prefix}animated`, animationName)
|
|
|
+
|
|
|
+ // When the animation ends, we clean the classes and resolve the Promise
|
|
|
+ function handleAnimationEnd(event) {
|
|
|
+ event.stopPropagation()
|
|
|
+ node.classList.remove(`${prefix}animated`, animationName)
|
|
|
+ resolve('Animation ended')
|
|
|
+ }
|
|
|
+
|
|
|
+ node.addEventListener('animationend', handleAnimationEnd, { once: true })
|
|
|
+ })
|
|
|
+ },
|
|
|
}
|