Jump to content
Search Community

Sequential Block and Vector Change with ScrollTrigger: Stuck at the First Block

Semih test
Moderator Tag

Recommended Posts

hi @Semih to be honest I'm not sure what you want to do here since in the code you are just selecting the first element with querySelector adding an active class to it and removing it when onLeaveBack ,

 

for a starting point you need to use the gsap.context() inside your useEffect or useLayoutEffect and here is a demo of how it works with react/next  https://gsap.com/docs/v3/GSAP/gsap.context()#react-demo 

 

or you can use useGSAP() hook its easier  https://gsap.com/resources/React#usegsap-hook-

 

something like this https://stackblitz.com/edit/stackblitz-starters-r9fccn?file=src%2FApp.js

 

Here's just pinning the .sas div with one ScrollTrigger and the other loop to toggle the class active between them 

Link to comment
Share on other sites

Hi,

 

I'm not sure I follow exactly what you're trying to do, but as @Toso shows in his demo, the main issue here is the fact that you're using onToggle in a wrong way and that you're not doing proper cleanup of the ScrollTrigger instance that pins the element.

 

Either use GSAP Context:

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

 

Or use our new useGSAP hook to simplify things quite a bit:

https://gsap.com/resources/React

 

Here is a demo using useGSAP for that result:

https://stackblitz.com/edit/stackblitz-starters-sz6hxj?description=A create-react-app project based on react and react-dom&file=src%2FApp.js&title=React Starter

 

Hopefully this helps.

Happy Tweening!

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