Jump to content
Search Community

Animation to continue after being displayed again

geholger test
Moderator Tag

Recommended Posts


first: thanks for this great plugin to make animations awsome :-). 

Here's what I am trying to achieve:
I have a web page (based on react) containing different tabs. In one of the tabs, I am running component with a gsap animation. If I switch to a different tab, I would like the animation to continue so that when I am returning to the tab that contains the animation the animated element is on a different position.

The (quick and dirty) codepen shows the problem. If you run it, the box just moves along the path. Clicking on "Show other component" will show another component (just some simple text). Clicking on the button again returns to the animated component. But this time, the box is not moving anymore. 


Any ideas how this could be achieved?


Best regards,


See the Pen MWEqrNK by geholger (@geholger) on CodePen

Link to comment
Share on other sites

I'm not a React guy (@OSUblake is our resident expert - I'm sure he'll chime in), but I think it's behaving that way because your code only creates the animation on the first run, and you've got conditional logic to skip it if "added" is true. When your component re-renders, it's an entirely different element now. So GSAP is indeed running its animation still, but it's on an element that no longer exists visibly in the DOM. 


There are probably many ways to solve this. If you can't prevent React from re-rendering that element in this situation, you could just create a fresh animation on that new object, but copy the totalTime() from the original one and set it on the new one before killing the old one. Sorta like this: 

See the Pen qBPMLRN?editors=0010 by GreenSock (@GreenSock) on CodePen

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