Jump to content
Search Community

Problem with ScrollTrigger Pinning - pin jumps to end of trigger

The_Orange_Dot test
Moderator Tag

Recommended Posts

Hi, I'm somewhat new here and I'm currently having problems with the ScrollTrigger plugin's pin function. For some reason, when the trigger is fired, thing I'm trying to pin to the top of the screen jumps down to the end of the scroll trigger. But when I scroll back up, the pin would work somewhat fine. I started a new project to test it out on Nextjs and it still jumps, but when i had this in codepen it worked flawlessly. I've added a screenshot of the code (with inline styling so you can see it all on one screenshot) and video link below. 

 

Thanks in advanced!

 

Here's a link to the problem on youtube:

 

32320226_Screenshot2023-01-05at9_56_35.thumb.png.b54740bd832f84c6d5ff6ad97ee8dba6.png

 

 

 

See the Pen KKBNVqK by the-orange-dot (@the-orange-dot) on CodePen

Link to comment
Share on other sites

Hi @The_Orange_Dot and welcome to the GreenSock forums!

 

This most likely is related with React's strict mode. When using GSAP in a React app (or it's ecosystem such as NextJS and Gatsby for example) we strongly recommend using GSAP Context:

https://greensock.com/docs/v3/GSAP/gsap.context()

 

Here is a setup using React with the same markup you have and you can see it works OK:

https://stackblitz.com/edit/react-d1gu6j?file=src%2Fstyle.css,src%2FApp.js

 

Also take a look at this guide:

Finally you can see these collections in order to see how to get started with GSAP in a React App:

 

React

https://stackblitz.com/@GreenSockLearning/collections/gsap-react-starters

 

NextJS

https://stackblitz.com/@GreenSockLearning/collections/gsap-nextjs-starters

 

Let us know if you have more questions.

 

Happy Tweening!

  • Thanks 1
Link to comment
Share on other sites

Just to be clear, the problem is most likely caused by the fact that your useEffect() is getting called MULTIPLE times (React 18+ started doing that), so you're creating duplicate ScrollTriggers that are fighting with each other for control of the same element(s). You're not doing proper cleanup to revert/kill the old ones before creating the new ones. The gsap.context() method makes cleanup super easy. I bet once you use that, your problem will go away. 

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...