Skip to content

Commit

Permalink
scrollend event order
Browse files Browse the repository at this point in the history
  • Loading branch information
clementroche committed Dec 27, 2024
1 parent 7d2abea commit 586dd8d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/core/src/lenis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,15 +674,17 @@ export class Lenis {
onComplete?.(this)
this.userData = {}

this.options.wrapper.dispatchEvent(
new CustomEvent('scrollend', {
bubbles: this.options.wrapper === window,
// cancelable: false,
detail: {
lenisScrollEnd: true,
},
})
)
requestAnimationFrame(() => {
this.options.wrapper.dispatchEvent(
new CustomEvent('scrollend', {
bubbles: this.options.wrapper === window,
// cancelable: false,
detail: {
lenisScrollEnd: true,
},
})
)
})

// avoid emitting event twice
this.preventNextNativeScrollEvent()
Expand Down
4 changes: 4 additions & 0 deletions playground/core/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ document
// console.log('scrollend')
// })

window.addEventListener('scroll', (e) => {
console.log('window scroll', e)
})

window.addEventListener('scrollend', (e) => {
console.log('window scrollend', e)
})
Expand Down

0 comments on commit 586dd8d

Please sign in to comment.