Reinis Posted February 1 Share Posted February 1 Greetings! I have run into this problem which seems quite trivial but I cannot find a solution. Please take a look at the demo. As you see I have a whole page wrapper pinned for two animations, the first one happens as expected but the second one I want to be started at a position of "center center" happens to start 500px earlier which is the duration of the previous animation. Is there any chance to take that duration into account when calculating the starting point of the second animation? Thanks in advance! See the Pen yLwKoEV by Reinis-Meulis (@Reinis-Meulis) on CodePen Link to comment Share on other sites More sharing options...
mvaneijgen Posted February 1 Share Posted February 1 Yes, you can add the total distance of the previous ScrollTrigger to the start of the next ScrollTrigger. Hope it helps and happy tweening! See the Pen rNRdGYr?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen And here a more elaborate setup See the Pen qBLRzVX?editors=0010 by GreenSock (@GreenSock) on CodePen 1 Link to comment Share on other sites More sharing options...
Reinis Posted February 1 Author Share Posted February 1 Thanks @mvaneijgen! It works as expected now. I will have to adapt it quite a bit as in my project I have multiple types of sections and animations for them and they can be used or not used in any order on each page but that's doable. 1 Link to comment Share on other sites More sharing options...
Solution akapowl Posted February 1 Solution Share Posted February 1 While you certainly can add those calculations to the start for each of your ScrollTriggers within that pinned element as shown above by Mitchel, actually you do not have to do that. ScrollTrigger does have a built in property to do exactly that for you in cases as such: pinnedContainer Quote pinnedContainer Element | String - If your ScrollTrigger's trigger/endTrigger element is INSIDE an element that gets pinned by another ScrollTrigger (pretty uncommon), that would cause the start/end positions to be thrown off by however long that pin lasts, so you can set the pinnedContainer to that parent/container element to have ScrollTrigger calculate those offsets accordingly. Again, this is very rarely needed. Important: nested pinning is not supported, so this feature is only for non-pinning ScrollTriggers (added in 3.7.0) https://gsap.com/docs/v3/Plugins/ScrollTrigger/ So the demos below with that property on the ScrollTriggers set to the pinned wrapping element should technically behave exactly the same as those with the calculations for the start shown above. As I see he's been sharing that one demo a couple of times before, I'll also ping @Rodrigo just to make him aware. Of course there's absolutely nothing wrong with calculating things like that, it's just a different way to achieve the same result - but why do it when you can also let ScrollTrigger handle itself [Edit: except for maybe edge cases where you'd have to add some calculations anyway]. 🙃 See the Pen mdoxqNL by akapowl (@akapowl) on CodePen See the Pen MWxVrgw by akapowl (@akapowl) on CodePen 2 1 Link to comment Share on other sites More sharing options...
Reinis Posted February 1 Author Share Posted February 1 I was trying to use that pinnedContainer before starting this topic and it had no visible effect on this in my actual project. Dunno why. Link to comment Share on other sites More sharing options...
Reinis Posted February 1 Author Share Posted February 1 Ok, I rewrote the logic of assigning timelines to elements and now the pinnedContainer param works fine too. Thanks @akapowl! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now