diff --git a/src/composables/useInfiniteScroll.js b/src/composables/useInfiniteScroll.js index 018ca24..9e92f3d 100644 --- a/src/composables/useInfiniteScroll.js +++ b/src/composables/useInfiniteScroll.js @@ -179,19 +179,18 @@ export const useInfiniteScroll = (options = {}) => { scrollY: state.scrollY + deltaY, duration: 1, ease: 'expo.out', + onUpdate: async () => { + const newViewportIndex = calculateVisibleViewport(state.scrollY) + if (newViewportIndex !== state.currentViewportIndex) { + state.currentViewportIndex = newViewportIndex + const rangeStart = newViewportIndex - bufferSize + const rangeEnd = newViewportIndex + bufferSize + + await loadViewportsInRange(rangeStart, rangeEnd) + cleanupViewports() + } + }, }) - - const newViewportIndex = calculateVisibleViewport(state.scrollY) - - if (newViewportIndex !== state.currentViewportIndex) { - state.currentViewportIndex = newViewportIndex - - const rangeStart = newViewportIndex - bufferSize - const rangeEnd = newViewportIndex + bufferSize - - await loadViewportsInRange(rangeStart, rangeEnd) - cleanupViewports() - } } // Attach the virtual-scroll listener once Lenis is ready