Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Sanjero

Issue with GSAP and jQuery

Recommended Posts

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(00);
  };
}
 
I'm using:
GSAP 3.7.1
and
 
Thanks in advance.
 
 

See the Pen oNwvJKY by Sanjero (@Sanjero) on CodePen

Link to comment
Share on other sites

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

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

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

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

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

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

Hi,

 

I finally fixed it, that was a bug in my code.

 

Thanks.

 

Ali

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×