Jump to content
Search Community

Calculating start position for secondary ScrollTrigger on pinned section

DouggieO test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

Just when I think I have ScrollTrigger mastered...

 

I'm trying to apply a parallax effect to a section (of unpredictable height) that also gets pinned. Thus, I need the parallax tween to pause while the section is pinned. My approach is 3 ScrollTriggers: 1.) for the pin, 2.) for the parallax tween before the pin, and 3.) for the parallax tween after the pin. 

 

The problem I'm running into is with ScrollTrigger 3—how can I calculate the start position? 

 

I came up with a solution in this codepen, adding .5% to the pin ScrollTrigger's start position.  But I'm honestly not quite sure why it's working, or how brittle it is. Is there a better approach to this problem?

 

See the Pen GRzEvXZ by doug-osborne (@doug-osborne) on CodePen

Link to comment
Share on other sites

  • Solution

It looks like you were creating your ScrollTriggers out of order and using a endTrigger element below a pinned one which is sorta overcomplicating things - I'd do it like this: 

See the Pen mdvwpOb?editors=0010 by GreenSock (@GreenSock) on CodePen

 

Notice I'm using:

start: (self) => self.previous().end 

Which just takes the previous ScrollTrigger's end value so that this one start immediately after that one. Makes it super easy to kinda piggy-back on the calculations that are done for the previous one and ensure that they're always back-to-back. 

 

Does this give the result you were after? 

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