Jump to content
Search Community

Scrub not working in React

andoivrjrev test
Moderator Tag

Recommended Posts

I have implemented a horizontal scroll for my React App (next.js). 

Works all fine, but the scroll is not catching smooth of with scrub, instead it is instand like a "normal" scroll.

This is the crucial part of my app, where the scroll happens:

 

  const scrollTriggerRef = useRef(null);
  useLayoutEffect(() => {
    if (!horizontalScroll) return;

    let ctx = gsap.context(() => {
      gsap.registerPlugin(ScrollTrigger);
      const scrollTimeline = gsap.timeline({
        scrollTrigger: {
          trigger: scrollTriggerRef.current,
          start: "top top",
          end: "+=9000px",
          scrub: 2,
        },
      });
      scrollTimeline.to(scrollContainerRef.current, {
        x: -scrollContainerRef.current.scrollWidth,
      });
    }, scrollTriggerRef);
    return () => ctx.revert();
  }, []);


If nobody knows the answer right on point, I will provide a minimum demo :).

Thanks guys!

Link to comment
Share on other sites

That's the right scrub syntax. It's important to specify a linear ease though.

Maybe try this and see how it looks? If it's not working pop us a minimal demo, thanks.
 

gsap.to(scrollContainerRef.current, {
  x: -scrollContainerRef.current.scrollWidth,
  ease: "none" // important,
  scrollTrigger: {
    trigger: scrollTriggerRef.current,
    start: "top top",
    end: "+=9000px",
    scrub: 2,
  },
});

 

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