OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

GSAP ScrollTrigger does not work correctly

  • Thread starter Thread starter Pavlo Posternak
  • Start date Start date
P

Pavlo Posternak

Guest
I am a newbie to GSAP animation library. and I have a small issue to use it on my landing pages.

https://drive.google.com/file/d/15RwlGz9zfjE65VxbMa-eKUqGawVK3aPQ/view?usp=sharing

ScrollTrigger has an issue while I visit different pages. I am using gsap in b2b page. it works well after I refresh this page. but normally user visit Home first and then come to this b2b page and the scrolltrigger works not correctly as you can see my video. I am so stuck with this issue.

Code:
  const [step, setStep] = useState(0);
  const [progress, setProgress] = useState(0);

  useEffect(() => {
    const numImages = products.length;

    const tl = gsap.from(".b2b .product", {
      scrollTrigger: {
        trigger: ".layout-paragraph.product .layout-title .sub-title",
        start: "top top",
        end: () => `+=${numImages * 120}%`,
        scrub: true,
        pin: ".landing-layout.container.b2b",
        onUpdate: (self) => {
          setStep(Math.floor(self.progress * numImages));
          setProgress(Math.floor(self.progress * numImages * 100));
        },
        onLeave: () => {
          setStep(numImages - 1);
        },
        onLeaveBack: () => {
          setStep(0);
        },
      },
      ease: "none",
    });
    return () => {
      tl?.kill();
    }
  }, []);

What do I make a mistake as you guess? Any help would be great.

<p>I am a newbie to GSAP animation library. and I have a small issue to use it on my landing pages.</p>
<p><a href="https://drive.google.com/file/d/15RwlGz9zfjE65VxbMa-eKUqGawVK3aPQ/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/15RwlGz9zfjE65VxbMa-eKUqGawVK3aPQ/view?usp=sharing</a></p>
<p>ScrollTrigger has an issue while I visit different pages. I am using gsap in b2b page. it works well after I refresh this page. but normally user visit Home first and then come to this b2b page and the scrolltrigger works not correctly as you can see my video. I am so stuck with this issue.</p>
<pre><code> const [step, setStep] = useState(0);
const [progress, setProgress] = useState(0);

useEffect(() => {
const numImages = products.length;

const tl = gsap.from(".b2b .product", {
scrollTrigger: {
trigger: ".layout-paragraph.product .layout-title .sub-title",
start: "top top",
end: () => `+=${numImages * 120}%`,
scrub: true,
pin: ".landing-layout.container.b2b",
onUpdate: (self) => {
setStep(Math.floor(self.progress * numImages));
setProgress(Math.floor(self.progress * numImages * 100));
},
onLeave: () => {
setStep(numImages - 1);
},
onLeaveBack: () => {
setStep(0);
},
},
ease: "none",
});
return () => {
tl?.kill();
}
}, []);
</code></pre>
<p>What do I make a mistake as you guess? Any help would be great.</p>
 

Latest posts

Online statistics

Members online
0
Guests online
4
Total visitors
4
Top