Jump to content
Search Community

Syntactic heritage of GSAP version 2

Alexandr Tyurin test
Moderator Tag

Go to solution Solved by OSUblake,

Recommended Posts

Greetings!

I have a question about GSAP 3 syntax. Interested in a way to specify the duration. Below are 2 options for specifying the duration of the animation:

1. gsap.to(".rect", 3, {rotate: 90});

2. gsap.to(".rect", {duration: 3, rotate: 90});

the first variant was in the second version of GSAP, the second variant appeared in the 3rd version.

The question is:

The first option is more concise and sometimes convenient. But there are fears that the first method is outdated and sooner or later will not work in new versions.

Or fears are in vain and both methods will remain in the future? Which way do developers go - leave variability or try to get rid of redundancy?

Link to comment
Share on other sites

  • Solution

Your fears are correct. Don't expect the first way to work in v4. The first way only works now because of the backwards compatibility with v2. Internally it's adding the duration like v3. 

 

I know the first way was simpler, but there are a lot of benefits with having the duration in the vars, for example, you can use function based values. That is not possible using the first way.

 

gsap.to(".box", {
  x: 500,
  duration: i => 0.5 + i * 0.5
})

 

  • Like 2
Link to comment
Share on other sites

Yep, over the years I've developed a pretty strong opinion about this - duration belongs in the vars object for a bunch of reasons that outweigh the convenience of not having to type "duration:" :)

 

More readable, more flexible (as Blake showed), and it keeps the critical information about the animation in a single object which can come in handy when passing it around. 

 

So yeah, in v4 and later, that old legacy syntax won't work anymore. Gotta modernize the syntax and push people toward a better direction. 

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