garyw Posted November 23, 2019 Share Posted November 23, 2019 I use killChildTweensOf in SPA web apps to make sure that all animations are terminated before swapping out a page. With GSAP 3, this method is gone. Is there a separate utility function that does this? I can't update to GSAP 3 without this function. Link to comment Share on other sites More sharing options...
GreenSock Posted November 24, 2019 Share Posted November 24, 2019 Oh sure, here's a function you can use that does exactly the same thing (but for GSAP 3): function killChildTweensOf(parent, complete) { var parents = gsap.utils.toArray(parent), i = parents.length, _isDescendant = function(element) { while (element) { element = element.parentNode; if (element === parent) { return true; } } }, j, tweens, targets; if (i > 1) { while (--i > -1) { killChildTweensOf(parents[i], complete); } return; } parent = parents[0]; tweens = gsap.globalTimeline.getChildren(true, true, false); for (i = 0; i < tweens.length; i++) { targets = tweens[i].targets(); j = targets.length; for (j = 0; j < targets.length; j++) { if (_isDescendant(targets[j])) { if (complete) { tweens[i].totalProgress(1); } tweens[i].kill(); } } } } Is that what you need? 1 Link to comment Share on other sites More sharing options...
garyw Posted November 25, 2019 Author Share Posted November 25, 2019 Yes, thank you very much! Link to comment Share on other sites More sharing options...
Calsa Posted February 23, 2021 Share Posted February 23, 2021 Maybe I missed it in the documentation, but was this ever added to the official GS codebase with a different function name, or do we still need to include this function to use it? I know there is a killTweensOf, but it does not seem to propagate down to children. My goal being to call this on the master node of an SVG group and kill all children when reloading page sections. I rather not include extra code, if a native function is already hiding somewhere in GS. Link to comment Share on other sites More sharing options...
GreenSock Posted February 23, 2021 Share Posted February 23, 2021 4 hours ago, Calsa said: I know there is a killTweensOf, but it does not seem to propagate down to children. My goal being to call this on the master node of an SVG group and kill all children when reloading page sections. Correct - it is not supposed to find and kill all tweens of any descendant nodes. That is by design. 4 hours ago, Calsa said: was this ever added to the official GS codebase with a different function name, or do we still need to include this function to use it? No, because one of the goals with GSAP 3 was to make it smaller and slice out some of the chunks of code that almost nobody used so that everyone can benefit. killChildTweensOf() is one of those methods, but as you can see above, it's quite easy for you to add the functionality yourself. In my opinion, that's a much better engineering decision because the 99.999% of users who never use it don't end up paying a kb tax for its inclusion, but people like you who really appreciate that functionality can just leverage an external function. Make sense? Good question, though. 2 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