Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Joe Hakooz

Remove Element from DOM - Does TweenMax still run?

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.

Thanks!

Link to post
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:

 

http://api.greensock.com/js/com/greensock/TweenLite.html#killTweensOf()

Link to post
Share on other sites

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

 

Solution

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

 

TweenMax.killAll();

 

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

Link to post
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.

×