pirco Posted September 12, 2022 Share Posted September 12, 2022 the demo for anchor links to sections isn't quite working for me. assuming that the individual menu items in the nav should highlight according to the section being displayed in the viewport, only the first and second menu item get highlighted but the second menu item stays highlighted when you keep scrolling. even when you use the anchor links to scroll to sections 3, 4 and 5. this is in chrome 105 and safari 15 on mac. or is it just me? greensock_scrolltriger_anchor_links_demo.mov See the Pen bGVjLwG by GreenSock (@GreenSock) on CodePen Link to comment Share on other sites More sharing options...
Rodrigo Posted September 12, 2022 Share Posted September 12, 2022 Hi @pirco and welcome to the GreenSock forums! It's like that by design: // --- RED PANEL --- gsap.from(".line-1", { scrollTrigger: { trigger: ".line-1", scrub: true, start: "top bottom", end: "top top", onEnter: () => setActive(links[0]), onEnterBack: () => setActive(links[0]), }, scaleX: 0, transformOrigin: "left center", ease: "none" }); // --- ORANGE PANEL --- gsap.from(".line-2", { scrollTrigger: { trigger: ".orange", scrub: true, pin: true, start: "top top", end: "+=100%", onEnter: () => setActive(links[1]), onEnterBack: () => setActive(links[1]), }, scaleX: 0, transformOrigin: "left center", ease: "none" }); // --- PURPLE/GREEN PANEL --- var tl = gsap.timeline({ scrollTrigger: { trigger: ".purple", scrub: true, pin: true, start: "top top", end: "+=100%" } }); As you can see the ScrollTrigger instance for the final panels doesn't set the active class on the links. Happy Tweening!!! Link to comment Share on other sites More sharing options...
pirco Posted September 13, 2022 Author Share Posted September 13, 2022 now it all makes sense! thank you Link to comment Share on other sites More sharing options...
GreenSock Posted September 13, 2022 Share Posted September 13, 2022 I'm actually not sure who built that, but here's how I assume you wanted it to work: See the Pen xxjErmp?editors=0010 by GreenSock (@GreenSock) on CodePen Notice I'm using a standalone ScrollTrigger to track each section (when its top would hit the top of the viewport) and then just tap into its "start" value to scroll there. I'm also toggling the active class when the sections hit the middle. 2 Link to comment Share on other sites More sharing options...
pirco Posted September 13, 2022 Author Share Posted September 13, 2022 that is EXACTLY how I assumed it would work. this is fantastic, Jack. Thank you. you could replace that demo with your new one 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