dataease/core/core-frontend/src/utils/runAnimation.ts

27 lines
930 B
Java
Raw Normal View History

2023-10-23 22:00:14 +08:00
export default async function runAnimation($el, animations = []) {
const play = animation =>
new Promise<void>(resolve => {
const { animationTime, value = '', isLoop } = animation
$el.style.setProperty('--time', animationTime + 's')
$el.classList.add(value, 'animated', utilsHandle(isLoop))
const removeAnimation = () => {
$el.removeEventListener('animationend', removeAnimation)
$el.removeEventListener('animationcancel', removeAnimation)
$el.classList.remove(value, 'animated', utilsHandle(isLoop))
$el.style.removeProperty('--time')
resolve()
}
$el.addEventListener('animationend', removeAnimation)
$el.addEventListener('animationcancel', removeAnimation)
})
for (let i = 0, len = animations.length; i < len; i++) {
await play(animations[i])
}
}
function utilsHandle(isLoop) {
return isLoop ? 'infinite' : 'no-infinite'
}