KST Posted July 4, 2021 Share Posted July 4, 2021 Hi, Does gsap.getById() only work once? After the first time, it returns undefined. See the Pen ExmjRep by tiffk935 (@tiffk935) on CodePen Link to comment Share on other sites More sharing options...
GreenSock Posted July 4, 2021 Share Posted July 4, 2021 Yes, GSAP automatically releases animations for garbage collection shortly after they complete, so getById() will only find animations that are active or haven't begun yet. Otherwise, if kept all animations around just in case you're gonna call getById() to find one, it could quickly clog up the system and lead to memory leaks. If you need to maintain a reference to an animation even after it completes, you should use a variable like this: let myTween = gsap.to(obj, {id: "myTween", duration: 1, x: 100}); So in your demo, you were trying to getById() a tween that already completed (the 2nd click), thus it had already been released for garbage collection. Does that clear things up? 1 Link to comment Share on other sites More sharing options...
KST Posted July 4, 2021 Author Share Posted July 4, 2021 Thanks. 😀 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now