Jump to content
Search Community

Next.js, Scrolltrigger doesn't work when navigate

antonio iodice test
Moderator Tag

Recommended Posts

Could you provide a minimal demo that clearly illustrates the issue? The one you provided doesn't seem to have any way to navigate anywhere, so we can't easily replicate the problem. 

 

Also, you forgot to add an empty array to your useEffect() dependencies Array. 

useEffect(() => {
  // code
}, []); // <-- IMPORTANT! Otherwise, it'll re-run on every render.

 

React Starter Stackblitz (please read this article!)

 

Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. 

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

 

There is not a lot we can do when it comes to live sites.

 

The only thing I can think of is that you are not reverting your animations when the page gets unmounted. You can use the cleanup function in the effect hooks to do that:

useLayoutEffect(() => {
  const ctx = gsap.context();
  return () => ctx.revert();
}, []);

Another possibility is that you are using page transitions, you need to know exactly when those are completed in order to create the ScrollTrigger instances. Have you tried setting markers to true in order to see where the markers are and, if the ScrollTrigger instances are being created at all?

 

We have this example using page transitions in Next:

https://stackblitz.com/edit/nextjs-13cw4u

 

Hopefully this helps.

Happy Tweening!

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.
×
×
  • Create New...