drei icon indicating copy to clipboard operation
drei copied to clipboard

GSAP Not working in ScrollControls Html

Open pradeepselva204 opened this issue 2 years ago • 3 comments

GSAP Not working in ScrollControls Html.

pradeepselva204 avatar Feb 25 '23 13:02 pradeepselva204

Can you provide an example using codesandbox ? I think you need to use https://greensock.com/docs/v3/Plugins/ScrollTrigger/static.scrollerProxy()

clementroche avatar Mar 01 '23 10:03 clementroche

I second this, gsap scrollTrigger is unable to read the HTML in the <Scroll html>, classes, ids or refs.

IhsenBen avatar Feb 18 '24 19:02 IhsenBen

I found a workaround to bind the Scrolltrigger to the ScrollControls. You need to pass the fixed.parentElement to the Scrolltrigger as a scroller. GSAP ScrollTrigger.scroller

fixed is the sticky div, and its parent has the overflow auto.

image

  const {fixed} = useScroll();

  useGSAP(() => {
    const boxes = gsap.utils.toArray('.box') as HTMLElement[];
    boxes.forEach(box => {
      gsap.to(box, {
        x: 300,
        rotation: 360,
        scrollTrigger: {
          trigger: box,
          scrub: true,
          scroller: fixed.parentElement,
        }
      })
    });
  }, );

Demo: https://r3f-scrolltrigger-scrollcontrols.vercel.app/ Full Test Repo: https://github.com/AxiomeCG/r3f-scrolltrigger-scrollcontrols

AxiomeCG avatar Mar 13 '24 08:03 AxiomeCG