Sanjero Posted August 29, 2021 Share Posted August 29, 2021 Hi, I have a issue with using GSAP and jQuery at same time. My GSAP code is working fine without jQuery but once I import jQuery to the index page I face the below strange behavior: When I refresh the page, GSAP losing the scroll position. Please open the below URL and scroll down to see the section animations, then refresh the page and try scrolling from top, you will see the issue. I used the below code to prevent the browser from saving the scroll position on refreshing page, which that works for the browser but for GSAP doesn't work and GSAP losing the scroll position which is because of jQuery I think. if (history.scrollRestoration) { history.scrollRestoration = "manual"; } else { window.onbeforeunload = function () { window.scrollTo(0, 0); }; } I'm using: GSAP 3.7.1 and https://code.jquery.com/jquery-3.6.0.min.js Thanks in advance. See the Pen oNwvJKY by Sanjero (@Sanjero) on CodePen Link to comment Share on other sites More sharing options...
GreenSock Posted August 30, 2021 Share Posted August 30, 2021 First of all, GSAP and ScrollTrigger have zero dependencies and I cannot imagine how loading jQuery could possibly break anything in GSAP/ScrollTrigger. They're loaded together on our site, actually I forked your demo and loaded jQuery and didn't see any such problems at all. I even added your code that jumps the window back to the top and never saw any problem at all. I scrolled down and hit "refresh" on the browser and it all worked perfectly from what I saw. What am I missing? Can you provide specific steps to reproduce the problem? Link to comment Share on other sites More sharing options...
Sanjero Posted August 30, 2021 Author Share Posted August 30, 2021 Thank you for your reply. Don't try it on codepen, just paste the code in a HTML file, import the jquery then try. Link to comment Share on other sites More sharing options...
GreenSock Posted August 30, 2021 Share Posted August 30, 2021 10 hours ago, Sanjero said: Don't try it on codepen, just paste the code in a HTML file, import the jquery then try. Done. No problems whatsoever. Link to comment Share on other sites More sharing options...
Sanjero Posted August 30, 2021 Author Share Posted August 30, 2021 4 hours ago, GreenSock said: Done. No problems whatsoever. Thank you for your reply, I will try to figure the issue out and let you know. Link to comment Share on other sites More sharing options...
GreenSock Posted August 31, 2021 Share Posted August 31, 2021 Okay, sounds good. And again, adding jQuery to a project should have absolutely no effect whatsoever on GSAP, or at least I can't fathom how it could but if you find a scenario that's reproducible outside of your local environment we'll happily take a peek. Link to comment Share on other sites More sharing options...
Cassie Posted August 31, 2021 Share Posted August 31, 2021 If you can get it working on codepen you can export the files and open then as a local project! That helped me a few times when I was confused about how to set up my project. Link to comment Share on other sites More sharing options...
Sanjero Posted September 4, 2021 Author Share Posted September 4, 2021 Hi, I finally fixed it, that was a bug in my code. Thanks. Ali 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