Jump to content
Search Community

MotionPath circular animation jump after resize-rerender

Yunus Emre test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

codesandbox link: https://codesandbox.io/p/devbox/swing-6ljdq5?file=%2Fapp%2Fswing.tsx%3A178%2C24
full page view: https://6ljdq5-3001.csb.app/

(React.js, Next.js)
Hello!. I have this code dynamically generates random sized/positioned images on the screen, ensuring they don't overlap.
The swing animation is achieved using GSAP's MotionPath plugin. Swing motion is based on image width (vw).
When the window is resized, the component re-renders, so that the positions and sizes of the images are recalculated and stay responsive.
* But then it starts to jump in the swing motion in the images. What could be the problem?

Secondly, do you think I am using gsap correctly for swing and mouse-move animations. What to improve, any tips?

Link to comment
Share on other sites

Hi,

 

Your demo is not accessible:
 

Devbox not found

It's likely that the Devbox you're trying to access doesn't exist or you don't have the required permissions to access it.

 

Please be sure to make it public or better create it on Stackblitz.

 

Happy Tweening!

Link to comment
Share on other sites

  • Solution

Hi,

 

It seems that using revertOnUpdate: true does the trick:

useGSAP(() => {
  // ...
}, {
  scope: holder,
  dependencies: [windowWidth],
  revertOnUpdate: true // <- HERE
});

It seems that the problem stems from the fact that the previous instances of the cycling animations are not getting killed before creating a new one and the inline styles are throwing off the data for the new ones.

 

https://gsap.com/resources/React#config-object

 

Also as a friendly advice I'd debounce the resize handler and perhaps fade out/in the images because even without the jump the UI (which is great by the way! 🤩) looks odd with the images suddenly jumping when the new position is created.

 

Hopefully this helps.

Happy Tweening!

  • Like 1
  • Thanks 1
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...