Jump to content
Search Community

scrolltrigger use pin and once, but pin-spacer cause padding space when scroll back

MiffyWu test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

  • Solution

You're making one of the common ScrollTrigger mistakes - nesting ScrollTriggers inside of a timeline. That can't logically work because you can't have the parent timeline AND the scroll position both control the same playhead(s), as they could be going in different directions. So either separate out each tween into its own individual tween that has a ScrollTrigger on it, OR put your tweens into a timeline that has a ScrollTrigger applied to that timeline. 

 

As for once: true, you could do something like this instead: 

onLeave: self => {
  let max = ScrollTrigger.maxScroll(window), // record maximum scroll amount, and the current scroll position
      scroll = self.scroll();
  self.kill(true, true);
  self.scroll(scroll - (max - ScrollTrigger.maxScroll(window))); // adjust the scroll based on how much was lost when self.kill() was called.
}

 

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

 

(I didn't fix all your nested ScrollTriggers - you'll need to work through those). 

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