Jump to content
Search Community

scrollTrigger - Sidebar navigation implementation

tolka test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

I'm trying to build a side navigation, whereby the currently active section (this is the trigger) adds a class to the corresponding navigation element on the left.   My callbacks are working on scroll down the page, but on the way back up, nothing happens.  I've got scrub set to true & once set to false and can't work out why it's not working on scroll up.  Is there a better way to go abut implementing this, or am I missing something basic about how this should work.

Edit to add - the pen is working on codepen, but not in this preview window.

See the Pen abpaBex by tolkadot (@tolkadot) on CodePen

Link to comment
Share on other sites

  • Solution

Welcome to the forums, @tolka

  • toggleActions and scrub only apply to ScrollTriggers that have an animation associated with them which isn't the case in your demo. 
  • You inverted the .matchMedia() and .forEach(). You were creating a bunch of duplicate matchMedia strings. In other words, put the .forEach() inside your .matchMedia(), not the other way around.
  • There's no need to define once: false since that's the default.
  • You don't need to create a dummy gsap.from() tween that has no tweening properties - you can simplify it to ScrollTrigger.create(...)
  • You had an invalid "end" value ("bottom"). It should have two values where the first relates to the trigger, and the second to the scroller, like "bottom top". 
  • You were only using onEnter and onLeave which apply to forward scrolling, but you neglected to tap into onEnterBack and onLeaveBack callbacks. In my opinion, it'd be much simpler to just use an onToggle callback and check the "isActive" property to run your logic (see the CodePen below)

Is this what you're looking for? 

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

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