wangrong
2026-08-30 761e5c5fa871959f60e15c971c8d83f2b53d0af5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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'
}