Jump to content

Joe Hakooz

Remove Element from DOM - Does TweenMax still run?

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Quick question here, sorry if this is answered somewhere else (couldn't find an answer).


Simplified scenario...

Let's say I have a div "#container" with an image inside it. Then I attach a tween to the image which rotates it infinitely.


Then... using jQuery, I replace the contents of #container with a new image.


Will the Tween that was attached to the original image (which is now gone) continue to eat memory, or is it now eligible for garbage collection? Do I first need to "Kill" all of its tweens before removing it?


My real situation is much more complicated but that is the general idea.


Link to comment
Share on other sites

Removing the target of a tween from the DOM does not prevent the tween from running.

Consider the following example: http://jsfiddle.net/geekambassador/g9qNg/


The tween's onUpdate function will run after the object is removed. Check out killTweensOf() which you can run when you remove your objects:



Link to comment
Share on other sites

  • 2 weeks later...

I never thanked you for your answer... Thanks!



In my scenario, I'm running a bunch of separate files each containing a series of tweens. Kind of like loading external swfs in the good ol days.

When the user clicks the "load next animation" button, I simply call...




... then load my next file via AJAX and I'm good to go!

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.