Skip to content

Commit

Permalink
feat(useScroll): support scrollend event (#2716)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongmoumou committed Feb 18, 2023
1 parent a7238d8 commit f887255
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/core/useScroll/index.ts
Expand Up @@ -146,14 +146,19 @@ export function useScroll(
bottom: false,
})

const onScrollEnd = useDebounceFn((e: Event) => {
const onScrollEnd = (e: Event) => {
// dedupe if support native scrollend event
if (!isScrolling.value)
return

isScrolling.value = false
directions.left = false
directions.right = false
directions.top = false
directions.bottom = false
onStop(e)
}, throttle + idle)
}
const onScrollEndDebounced = useDebounceFn(onScrollEnd, throttle + idle)

const onScrollHandler = (e: Event) => {
const eventTarget = (
Expand Down Expand Up @@ -182,7 +187,7 @@ export function useScroll(
internalY.value = scrollTop

isScrolling.value = true
onScrollEnd(e)
onScrollEndDebounced(e)
onScroll(e)
}

Expand All @@ -193,6 +198,13 @@ export function useScroll(
eventListenerOptions,
)

useEventListener(
element,
'scrollend',
onScrollEnd,
eventListenerOptions,
)

return {
x,
y,
Expand Down

0 comments on commit f887255

Please sign in to comment.