Gsap ScrollTrigger and a click event using scrollTop highlighting menu items
I've a menu where each item corresponds to a
Click on an item, it adds a
But then I've added
Just wondering how people would approach this, because at the moment my solutions feel a bit hacky. Eg: I'm considering disabling
Here's a codepen
https://codepen.io/nwoodward/pen/NWBmZgd?editors=0011
section div. Click on an item, it adds a
border-bottom, and scrolls somewhere vaguely near the element (because life, and scroll-padding, just can't be that easy). Simple stuff.But then I've added
ScrollTrigger to track which section I'm above when scrolling and change the active menu item accordingly. This unfortunately means that when you click a menu item, say item 4, it now scrolls to 4, but highlights menu items 1,2,3 and then 4 on the way there.Just wondering how people would approach this, because at the moment my solutions feel a bit hacky. Eg: I'm considering disabling
ScrollTrigger quickly after the click event, and then listening for a scrollend event to re enable it, or making the border-bottom transparent. There's a property to prevent animations overlapping: preventOverlaps but I've either implemented it wrong or it doesn't disable the callbacks (onEnter etc). Just think there must be a better solution I haven't thought of.Here's a codepen
https://codepen.io/nwoodward/pen/NWBmZgd?editors=0011

