Jump to content
Search Community

Pin sections in one place without scrub or layer

pysilla test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Hi,

 

Sorry for the late response. I'm not sure I follow your description of what you're trying to achieve.

 

Maybe something like this:

See the Pen KKpLdWW by GreenSock (@GreenSock) on CodePen

 

Also when using GSAP in React apps/environments we strongly recommend using GSAP Context for easy scoping and even easier cleanups:

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

 

Finally have a look to the resources in this page:

 

Hopefully this helps.

Happy Tweening!

Link to comment
Share on other sites

Hi @pysilla after ScrollTrigger was created I put in the following line to see what was going on and saw you where creating multiple ScrollTriggers for each section.

 

ScrollTrigger.defaults({
  markers: true,
});

Personally I like to keep things simple. I already have a ScrollTrigger, so why not hook the animation to that ScrollTrigger, then I can just add all the tweens to that timeline and I'm done!

 

So that is what I did, I moved your on update function to be part of a timeline and with some fancy staggers I fade in and out each section on scroll.  I've set the end trigger to an arbitrary value of 5000px, but you could easily change that to something else (the height of the section times the number of sections, maybe), oh and I've set your main ScrollTrigger instance to scrub: true, so it animates based on the users scroll. Is something like that what you're looking for? Hope it helps and happy tweening! 

 

https://stackblitz.com/edit/vitejs-vite-v38kcu?file=src%2FApp.jsx

  • Like 1
Link to comment
Share on other sites

Thank you for your time, probably it could be a good alternative :) 

 

Like it's in the title of this thread I wanted not to use scrub :)

I  really wanted the exact same effect like in my demo, but the animation starts too late (starts at the begining of the page even if it should start when it reaches the pinned section).

 

Do you think you could give me sobie advice how to start animation when it reaches pinned section ? Thank you :)

Link to comment
Share on other sites

  • Solution

Hi,

 

As @mvaneijgen mentions your current approach might be a bit more convoluted than it actually needs to be. On top of that you are creating a ScrollTrigger instance that is pinning the container of the panels before creating the ScrollTrigger instances for each panels, so basically that could be throwing off some of the calculations ScrollTrigger is making.

 

This approach seems cleaner and simpler:

See the Pen KKGwdWz by GreenSock (@GreenSock) on CodePen

 

Here is the same code but in a React app:

https://stackblitz.com/edit/vitejs-vite-s7gry6?file=src%2FApp.jsx

 

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