Jump to content
Search Community

Does a .fromTo animation "kill" itself upon completion?

Web Bae test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

mButton.addEventListener("click", (e: Event) => {

        let xDist = (e as PointerEvent).clientX - mButton.getBoundingClientRect().x
        let yDist = (e as PointerEvent).clientY - mButton.getBoundingClientRect().y

        gsap.set(circle, { left: xDist, top: yDist })
        gsap.fromTo(circle, { scale: 0, opacity: 1 }, { scale: 1, opacity: 0, duration: .5, ease: "ease.out" })
        console.log(gsap.globalTimeline.getChildren())
    })

 

I have a button that trigger as .fromTo on click. Animation is working great, gsap.globalTimeline.getChildren() only return the active animation(s) from console log statement.

 

My question: does the tween kill itself upon completion? Just wondering what the best practice is here? If it doesn't kill itself is it wise to call .kill() onComplete? Or maybe store the tween in a variable and check it if already exists? If it doesn't kill itself, is there a way to check how many tweens are still "alive"? OK that was 3 questions sorry about that one!

 

Thanks!

Keegan

Link to comment
Share on other sites

  • Solution

The global timeline has autoRemoveChildren set to true, thus whenever a child completes, it gets removed and made eligible for garbage collection, but if you keep your own reference around, obviously you can do whatever you want with that, like restart(), reverse(), whatever and it'll automatically get pushed back into the global timeline while playing. You do NOT need to worry about killing each tween you create. It's all automatic. Does that answer your question? 

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