Jump to content
Search Community

How to keep track of tweens?

ajmusiclion test
Moderator Tag

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

Hi. I am a beginner at using the GSAP JavaScript library. I would like to know if there is a way to keep track of all of the tweens executing on a web page. Is there a way to assign an ID to each tween on a web page? If so, do I store the IDs into an array? When I am done with a tween can I use that ID to "kill" it? Thank you.

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums,

 

If your intent is to kill all your animations at once, please see TweenMax.killAll()

 

https://greensock.com/docs/TweenMax/static.killAll()

 

To track individual tweens, yes you can assign them to a variable or push them into an Array.

var myTween = TweenMax.to(something, 1, {x:100});



//and then you can kill or control that animation using common methods such as



myTween.restart();

myTween.pause();

myTween.reverse();

myTween.kill();

someArray.push(myTween)

 

Also you can grab all tweens and put them in a timeline that you can then control or kill as a group using TimelineLite.exportRoot() https://greensock.com/docs/TimelineLite/static.exportRoot()

That's a fairly advanced concept and may not be super easy to grasp for beginners.

 

Definitely crack open the TweenMax docs and explore the methods in the left-hand nav. Its a great way to get an overview of the capabilities of the platform

https://greensock.com/docs/TweenMax/TweenMax() and find some stuff you may not know was possible. Don't worry about understanding everything the first time through. Just good to have some mental notes that you can follow up on later.

 

 

 

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