Sukru Posted December 22, 2022 Share Posted December 22, 2022 Hello, I added lightGallery framework to my gsap project, it works fine, but there is a scroll problem. When I turn off the lightbox, it shifts up and down. How can I prevent this? Can you help me? I guess scroll is not locking See the Pen YzjXZQW?authentication_hash=jVkpoNOKZYdA by pen (@pen) on CodePen Link to comment Share on other sites More sharing options...
Rodrigo Posted December 22, 2022 Share Posted December 22, 2022 Hi, Sorry to hear about the issues you're having but I'm not seeing any shift or jumps when testing that codepen in both chrome and firefox on Ubuntu 20 and 22. Can you be more specific about the OS and browser where you're seeing this behaviour? Finally you're using different versions for the GSAP core (3.10.0) and the plugins (3.11.4). Is worth mentioning that just today GSAP was updated to 3.11.4 which included a few fixes in ScrollTrigger and ScrollSmoother, so you might want to updated those dependencies on your local machine. Let us know if you have more questions. Happy Tweening! 1 Link to comment Share on other sites More sharing options...
Solution akapowl Posted December 22, 2022 Solution Share Posted December 22, 2022 Hello, I can see the issue described, but as Rodrigo mentioned, you will definitely need to update your GSAP version first; and yes, it looks like it is a problem because you can scroll while the gallery is open, and when it closes it will move back to the position it was before opening (or something along those lines). You will need to find the event working best for you, to toggle ScrollSmoother.paused() at the right time, if you want to disable the scroll while the gallery is open. https://greensock.com/docs/v3/Plugins/ScrollSmoother/paused() Here is a link to the events available with lightgallery: https://www.lightgalleryjs.com/docs/events/ Something like this maybe: See the Pen PoBqpeO by akapowl (@akapowl) on CodePen EDIT: Also, if you update the lightGallery version you are using to at least version 2.5.0, apparently an option comes available that lets you prevent the resetting of the scroll-position altogether which would likely make the blocking of the scroll unneccessary to begin with. Maybe something you'd want to consider. https://www.lightgalleryjs.com/docs/settings/#resetScrollPosition Quote resetScrollPosition boolean true Reset to previous scrollPosition when lightGallery is closed By default, lightGallery doesn't hide the scrollbar for a smooth opening transition. If a user changes the scroll position, lightGallery resets it to the previous value Minimum lightGallery version required: V2.5.0 3 Link to comment Share on other sites More sharing options...
Sukru Posted December 22, 2022 Author Share Posted December 22, 2022 @akapowl thank you very much 1 Link to comment Share on other sites More sharing options...
Fisher666 Posted March 27, 2023 Share Posted March 27, 2023 Hello! I had sort of a similar problem in Nuxt3 with Lightgallery and ScrollSmoother. Before closing Lightgallery, the page jumped to the top and then scrolled back to the gallery container. This occurred only when opening Lightgallery for the first time (still not acceptable ). ScrollSmoother.paused(true) in Lightgallerys onBeforeOpen hook didn't help, it paused on position 0. What did work was setting smooth() to 0 in onBeforeOpen and setting it back to a desired value in Lightgallerys onBeforeClose hook. But... if the gallery was opend while the page was still moving (smoothing), after closing, it jumped to the point where smoothing would end. I found a workaround to that, I'll post it below since this was the only post about the topic I found and it can help someone in the future. const position = ref(); function beforeOpen() { const smoother = ScrollSmoother.get(); position.value = smoother?.scrollTop(); smoother?.smooth(0); } function beforeClose() { const smoother = ScrollSmoother.get(); smoother?.scrollTop(position.value); ScrollTrigger.refresh(); smoother?.smooth(2); } 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