Adesh Posted January 12, 2023 Share Posted January 12, 2023 How can I keep my previous scroll position after refreshing the page? Currently, if a user scrolls to the bottom of the page and then refreshes the page, it will redirect to the top of the page. See the Pen oNLqgBm by GreenSock (@GreenSock) on CodePen Link to comment Share on other sites More sharing options...
GSAP Helper Posted January 12, 2023 Share Posted January 12, 2023 It looks like you're using a 3rd party scrolling library that's interfering with things most likely. We can't really support non-GreenSock products. I'd encourage you to first eliminate that 3rd party library from your project and see if it resolves things. If so, you know that's the culprit and you can contact the author to seek advice. You may also want to try explicitly setting the scrollRestoration value in the browser: if (history.scrollRestoration) { history.scrollRestoration = 'manual'; } Link to comment Share on other sites More sharing options...
Adesh Posted January 12, 2023 Author Share Posted January 12, 2023 Can you suggest me, How can i add smooth scroll to my website using gsap? Link to comment Share on other sites More sharing options...
Rodrigo Posted January 12, 2023 Share Posted January 12, 2023 Hi, GreenSock has the ScrollSmoother plugin for this: https://greensock.com/scrollsmoother/ What you can do with your current setup is to store in the browser's Local Storage the scroll position when the page is refreshed and check if that position is defined when loaded and apply that. But as mentioned before this is related to a third party library so you should check their API in order to do that. https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage https://developer.mozilla.org/en-US/docs/Web/API/Storage Happy Tweening! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now