Jump to content
Search Community

gsap.getById() only work once

KST test
Moderator Tag

Recommended Posts

 

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? 

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