Jump to content
Search Community

Adding scroll trigger functionality to navigate through slider not working

Caspert test
Moderator Tag

Recommended Posts

Hi,

 

I just saw the infinite slider of  GSAP, but I want to add another functionality, so when the user scrolls, the slides are snapping in view.

I added the ScrollTrigger functionality, but it seems it not working and I can't find the issue by myself.

 

So does anyone know how I can fix the issue, so the slider can also used with scroll, similar to how the prev and next buttons work?

 

// Use ScrollTrigger to control the slider with scroll
gsap.to(wrapper, {
  scrollTrigger: {
    trigger: wrapper,
    start: "top top",
    end: "bottom bottom",
    scrub: 1, // Controls the sensitivity of the scroll
  },
  onUpdate: (scrollTrigger) => {
    const progress = scrollTrigger.progress;
    const totalDuration = loop.totalDuration();
    const time = progress * totalDuration;
    loop.tweenTo(time);
  },
});

 

See the Pen bGZvKMW by Caspert (@Caspert) on CodePen

Link to comment
Share on other sites

Thank you for the response. That's a lot easier than I actually thought!
The only thing that I am seeing now is that it is really sensitive to the scroll, is there also a solution for, so it's a lot more sturdy. Something more like this example: 

See the Pen poYVREZ by Caspert (@Caspert) on CodePen

 

Can this be combined or adjusted with a property?

Link to comment
Share on other sites

Hi,

 

You can add a boolean check in order to allow one Observer callback at a time:

let isTweening = false;

// Observer instance
Observer.create({
  target: window,
  type: "wheel",
  onUp: () => {
    if (isTweening) return;
    isTweening = true;
    loop.previous({
      onComplete: () => isTweening = false,
      duration: 0.4,
      ease: "power1.inOut"
    });
  },
  onDown: () => {
    if (isTweening) return;
    isTweening = true;
    loop.next({
      onComplete: () => isTweening = false,
      duration: 0.4,
      ease: "power1.inOut"
    });
  },
});

 

Hopefully this helps.

Happy Tweening!

  • Like 1
Link to comment
Share on other sites

Thank you for the updated version. The only thing what I experience now is when I scroll and let go, it will move most of the time multiple slides. But I would like to just slide one at a time. Is that also possible? 

 

Already tried to make the duration longer, but this doesn't solve the issue.

See the Pen Babxwwj by Caspert (@Caspert) 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...