Jump to content
Search Community

Help Needed: scrollTrigger Defined Trigger is Stuck and Won't Move!

duu test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Hello everyone!
 

I'm encountering an issue where the trigger I have defined with scrollTrigger is stuck and won't move. I've spent a considerable amount of time trying to resolve this issue, but unfortunately, I've had no luck so far.

image.gif.d7e7d3ba3c9802fc3fbc14a676c8071d.gif

How can I resolve this issue to get the trigger moving as intended? I have prepared a demo page that reproduces the problem, which can be found at the following link:
 

https://stackblitz.com/edit/stackblitz-starters-uv18fb?file=app%2Fpage.tsx


I would really appreciate any help or guidance from the community on this. Thank you in advance for your time and assistance!

Link to comment
Share on other sites

Hi there! I see you're using React -

Proper animation cleanup is very important with frameworks, but especially with React. React 18 runs in strict mode locally by default which causes your useEffect() and useLayoutEffect() to get called TWICE.

 

Since GSAP 3.12, we have the useGSAP() hook (the NPM package is here) that simplifies creating and cleaning up animations in React (including Next, Remix, etc). It's a drop-in replacement for useEffect()/useLayoutEffect(). All the GSAP-related objects (animations, ScrollTriggers, etc.) created while the function executes get collected and then reverted when the hook gets torn down.

 

Here is how it works:

const container = useRef(); // the root level element of your component (for scoping selector text which is optional)

useGSAP(() => {
  // gsap code here...
}, { dependencies: [endX], scope: container }); // config object offers maximum flexibility

Or if you prefer, you can use the same method signature as useEffect():

useGSAP(() => {
  // gsap code here...
}, [endX]); // simple dependency Array setup like useEffect()

This pattern follows React's best practices.

 

We strongly recommend reading the React guide we've put together at https://gsap.com/resources/React/

 

Here's a fork of your project: 

https://stackblitz.com/edit/stackblitz-starters-hmmgbq?file=app%2Fpage.tsx

 

Is that better? 

Link to comment
Share on other sites

  • Solution

Hi @duu and welcome to the GSAP Forums!

 

What exactly are you trying to do? Is not really clear from this code what you're trying to achieve:

useGSAP(
  () => {
    const panels: HTMLElement[] = gsap.utils.toArray('.section');
    gsap.timeline({
      scrollTrigger: {
        trigger: panels[0],
        start: 'center center',
        end: 'bottom top',
        toggleActions: 'play none none reverse',
        markers: true,
        scroller: '.swiper-wrapper',
      },
    });
  },
  { scope: main.current }
);

Right now if I remove the above code from your demo the result is the same given the fact that you're using Swiper. Honestly IDK what you're trying to do here and how you want to integrate ScrollTrigger into this.

 

Keep in mind that ScrollTrigger by default uses the window element as scroller, but maybe here you're using a different one and you should use the scroller property from the ScrollTrigger config object:

scroller
String | Element - By default, the scroller is the viewport itself, but if you'd like to add a ScrollTrigger to a scrollable <div>, for example, just define that as the scroller. You can use selector text like "#elementID" or the element itself.

 

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