Skip to content

Commit

Permalink
chore: fix v-slideIn bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ileostar committed Mar 3, 2024
1 parent 7d349d0 commit 6d6e905
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/directive/v-slideIn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ function isBelowViewport(el: HTMLElement) {
}

function handleScroll() {
const elements = document.querySelectorAll('[v-slideIn]')
const elements = document.querySelectorAll('[v-slide-in]')
elements.forEach((el: any) => {
if (isBelowViewport(el))
return

const animation = map.get(el)
if (animation && !el.hasAttribute('v-slideIn-played')) {
if (animation) {
animation.play()
el.removeAttribute('v-slideIn')
el.setAttribute('v-slideIn-played', '') // Add a flag to mark the animation as played
el.removeAttribute('v-slide-in')
}
})
}
Expand Down Expand Up @@ -54,7 +53,7 @@ const vSlideIn: Directive = {
)
animation.pause()
map.set(el, animation)
el.setAttribute('v-slideIn', '') // 添加标记,表示需要进行动画
el.setAttribute('v-slide-in', '') // 添加标记,表示需要进行动画

window.addEventListener('scroll', handleScroll)
},
Expand Down

0 comments on commit 6d6e905

Please sign in to comment.