Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
BornToCreate

Diffrences between TimelineMax.to() and TweenMax.to()

Recommended Posts

Hi,

normaly I am adding Tweens to my Timeline with TimelineMax.add().

Is there any diffrence (performance etc.) between TimelineMax.to() and TimelineMax.add(TweenMax.to()) ?

Or is it just the same?

Link to comment
Share on other sites

.to() calls .add() so that's an extra function being called. Will you notice that, doubtful. You're comparing like millions of ops/sec to millions of ops/sec. I'd say it's better to use .to() just because it improves readability.

  • Like 4
Link to comment
Share on other sites

I would agree with Blake on this. If i can remember, Carl, also recommended just using the convenience methods to(), from(), etc instead of using add() with a TweenMax/Lite instance in it.

 

I had asked GreenSocks Mighty Carl about the same thing and he told me the following about add()

  • add() is tricky because although its super flexible, we only really use it for adding nested timelines and labels and perhaps the occasional callback without parameters.

  • For adding tweens to a timeline, the convenience methods (to(), from(), staggerFrom() etc)  do the exact same thing but with less code. The flexibility of the position parameter made append() and insert() totally obsolete. So no need to use add(TweenMax.to()) .. just use the convenience methods (to(), from(), staggerFrom() etc)

  • Besides nesting timelines the only unique thing add() can do is allow you to add an array of tweens and change the alignment. Like appendMultiple() and insertMultiple() used to do.

But Carl and Jack could explain it better than i ever could.

 

I also agree with Blake, that it helps with improving readability like Blake said above, when you use a convenience method like to() over add(TweenMax.to())

 

Also the difference between TimelineMax.to() and TweenMax.to() is that TimelineMax.to() is used in creating sequenced timelines, even though you could also use TweenMax by associating with a variable instance. But TimelineMax/Lite is the preferred method in creating timelines, especially nested timelines.

 

Here is a link to both in the GSAP Docs so you can see the differences between TweenMax.to() and TimelineMax.to():

Just my two cents, with a side of lint. :)

  • Like 4
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.
×