Jump to content
Search Community

GSAP ScrollTrigger/React - Animations don't work properly on first load

YoungDevR test
Moderator Tag

Recommended Posts

Hi GreenSock community!

I am working on a Reach website with GSAP fromTo animations. Everything works properly except for the first time the website loads.
I have tried looking into other similar GSAP posts, checking my props components, trying ScrollTrigger.refresh(), but it all did not help.


I have deployed a simplified version of the website on CodeSandBox: https://codesandbox.io/s/bold-beaver-x7zoz4?file=/src/App.js
I believe you only need to review the App.js component to see what happens.

There is a JPEG image on the website and a couple of Section components. The purpose of GSAP animation is to apply changes to the image's CSS transform properties on scroll. 

The animation is supposed to first translate the image up upon scrolling to the first section, then zoom in and fade in, then zoom out and return to opacity=1. If you scroll through the whole website and then scroll again, you will see how it is supposed to work. If you only load the website, you will see the erroneous output. 

I really hope someone can help me resolve this, I am running out of ideas (and time..)

Thank you!

See the Pen by (@) on CodePen

Link to comment
Share on other sites

You need to move all your tweens into one useEffect and create them in the correct order. Your code is extraordinarily hard to debug and I can't dedicate more time right now to this issue.

Please read the rest of the GSAP docs as well. You don't need to tween the "transform" property and should instead use the buiilt in gsap properties.

  • Thanks 1
Link to comment
Share on other sites

Quote

Please read the rest of the GSAP docs as well. You don't need to tween the "transform" property and should instead use the buiilt in gsap properties.


i.e.

 

gsap.to(elem, {
  x: 200,
  xPercent: 40,
  opacity: 0,
  scale: 3,
  rotation: 360
})

 

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