Jump to content
Search Community

Clear and kill

cookietran test
Moderator Tag

Recommended Posts

Could someone explain the difference between using kill() or clear() on a timeline? That is, besides kill() being able to kill individual tweens, lets assume we're using kill() on the entire timeline itself. The documentation is unclear (use kill to kill a tween; define kill?). If they're the same, then why use clear(), other than the timeline instance being preserved? And, I'm interested if either resets the positions of elements in a timeline to their beginning position, or what the best way to go about that is? Thanks!

Link to comment
Share on other sites

Hey cookietran and welcome to the GreenSock forums.

 

Clear empties a timeline so you can reuse it. Kill removes the timeline completely so it can be garbage collected - it can't be reused. 

 

5 hours ago, cookietran said:

I'm interested if either resets the positions of elements in a timeline to their beginning position, or what the best way to go about that is?

tl.progress(0) is the best way to go about that :) 

Link to comment
Share on other sites

9 hours ago, ZachSaucier said:

Kill removes the timeline completely so it can be garbage collected - it can't be reused. 

 

You can use an animation after kill. kill frees the animation up garbage collection. If you still have a reference to the timeline, then it obviously can't be freed for garbage collection, and you can play it again.

 

  • Like 1
Link to comment
Share on other sites

You can reuse anything that gets killed. It doesn't destroy the animation. It just stops it from playing and frees it up for garbage collection inside gsap's internal cache. It doesn't free it up for garbage collection if you still have a reference to it i.e. storing it in a variable.

 

See the Pen 5da1e4c25397934adc50b5a567620896 by osublake (@osublake) on CodePen

 

 

 

  • Like 2
Link to comment
Share on other sites

I definitely wouldn't recommend calling kill() on a tween/timeline that you plan to reuse later. Technically that can work sometimes, but:

  • It isn't intuitive. Killing is intended to make something dead :)
  • If the goal is to reuse it, I think it's far more clear to just pause() it.
  • Even if it technically works in some cases now, there's a chance that updates will be made in the future that would cause those cases not to work. 

 

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