Jump to content
Search Community

onInterrupt on nested timelines & tweens

StGewehr test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

Hi guys,

 

First of all, thank you for amazing tool!

 

My question is about the onInterrupt callback, I put them on multiple nested timelines. Then I ".kill ()" the root timeline and expect that ALL onInterrupt will be called. At the moment, it works only on the root.

 

Are my expectations wrong?

The idea is that I have some structure of nested objects, and each object returns its own part of the animation, and I want to use onInterrupt to do clean up inside this "node tree". Otherwise ... I have to find all the children and kill them one by one? Or keep references to them while preparing the timeline, which will result in dirty code.

 

Many thanks!

 

 

See the Pen abpdJKw by StGewehr (@StGewehr) on CodePen

Link to comment
Share on other sites

  • Solution

Welcome to the forums, @StGewehr! Thanks for being a Club member. 🙌

 

Yeah, onInterrupt isn't really supposed to be called for all descendants - GSAP is highly optimized for performance and when you kill() an animation it basically unhooks it from its parent timeline very quickly (using linked lists). If every timeline had to iterate through all its children whenever it's killed (which also happens when it's finished, of course, assuming autoRemoveChildren is true), it just seems rather wasteful. 

 

You can easily accomplish what you're looking for, though, with this helper function: 

function deepKill(tl) {
	tl.add && tl.getChildren(true, true, true).forEach(animation => animation.kill());
	tl.kill();
}

Just feed any animation into that to "deep-kill" it. If it's a timeline, it'll iterate through all its children/descendants and kill() each one and that'll trigger the onInterrupt as you were hoping. 

 

Does that clear things up? 

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