Jump to content
Search Community

Scrolltrigger Scrub problem when React State changes

alvsys

Go to solution Solved by OSUblake,

Recommended Posts

Posted

Hi!

I am using ScrollTrigger in React and I am experiencing the following problem:

When I update any React State and I use scrub:1(or any number), the animation is reset and it is possible to see it jumping.

This doesn't happen when scrubis set to true

I've tried different methods available in the guides and read many forum topics but I haven't had success.

I wonder if this is possible keep the position when there is a re-render?

 

I'd appreciate any help :) 

Thanks in advance

See the Pen WNdbVZL by alvsys (@alvsys) on CodePen.

  • Solution
Posted

Welcome to the forums @alvsys

 

Your useEffect needs an empty array on the end, otherwise it will recreate the animation on every state change. Be sure to check out our React guide.

 

 

 

  • Thanks 1
Posted

Hi @OSUblake, thank you very much! now it works like charm,

I checked lots of times for days and I couldn't see that detail :(  newbie mistake, I put the focus in the wrong stuff.

Much appreciated ?

Cheers!

  • Like 1

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