#give me the event to stop lenis scroll when changing page and the other event to restart the scroll
1 messages · Page 1 of 1 (latest)
In Astro, you can use the astro:after-swap event to control actions that occur immediately after the new page replaces the old page. This event can be used to override the default scroll restore for history navigation.
Here's an example of how you can use this event to reset the scroll position to the top left corner of the page for each navigation:
document.addEventListener('astro:after-swap', () => window.scrollTo({ left: 0, top: 0, behavior: 'instant' }))
This code listens for the astro:after-swap event and when it fires, it uses the window.scrollTo method to set the scroll position to the top left corner of the page. The behavior: 'instant' option ensures that the scroll happens immediately, without any smooth scrolling animation.
Please note that this is a general example and might need to be adjusted based on your specific use case and the behavior of the lenis scroll in your application.