Jump to content
Search Community

Position sticky panels with ScrollToPlugin and ScrollTrigger issues

aok test
Moderator Tag

Recommended Posts

I'm using `position: sticky` for some nice CSS only layered scrolling but I need to add in some scrollTo for some navigation. Unfortunately as you can see from the demo that the `scroll to` only works one way (it doesn't scroll you to the sections if you've passed them), I'm guessing how scrollToPlugin is getting the position to scroll to with the layered scrolling. Is there any way to use scrollToPlugin with this?

 

My intention is also to use ScrollTrigger for some active nav items BUT sometimes the start and end of the triggers are random off (if I scroll down then refresh etc) so I'm wondering if the position sticky is messing things up also.

 

Any advice is appreciated.

See the Pen wvZVbqG by richardcool (@richardcool) on CodePen

Link to comment
Share on other sites

Thanks for the help @Rodrigo – I've updated my original CodePen now.



I used one of the examples to pin the sections for the same desired effect and then grab the trigger using ScrollTrigger.getById and getting the trigger.start position to use on the scrollTo. This works great however on one of the panels (the orange one in my demo), that is longer than 100% height of the viewport, it scrolls to the bottom. This is due to the start position on the scrollTrigger being set to the bottom.

start: () => section.offsetHeight < window.innerHeight ? "top top" : "bottom bottom",

However, if I always set this to `"top top"` I can no longer scroll through the larger orange panel.

Link to comment
Share on other sites

Hi,

 

Maybe a different logic for every element that is not the first, instead of selecting the ScrollTrigger for the current element and using that start point, use the previous ScrollTrigger (if any) end point:

const menuLinks = gsap.utils.toArray("header ul li button");

menuLinks.forEach((elem, i) => {
  elem.addEventListener("click", function () {
    let target = elem.getAttribute("data-panel"),
        trigger = ScrollTrigger.getById(target);
    if (i > 0) {
      target = menuLinks[i - 1].getAttribute("data-panel");
      trigger = ScrollTrigger.getById(target);
    }

    gsap.to(window, {
      duration: 1,
      scrollTo: i > 0 ? trigger.end : trigger.start,
      overwrite: true
    });
  });
});

Hopefully this helps.

Happy Tweening!

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