Jump to content
Search Community

Change .vars:Object tweening property name dynamically

milkaWhat 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

Is it possible to change the .vars tweening property name? It doesn't seem to be accessible, and probably for a good reason.

 

If possible, in the end I want to be able to change tweening property from "x" to "y" with a conditional statement or vise versa.

 

In the Codepen I was trying to use coordPosY and coordPos to interchange "y" to "x". 

See the Pen JyYmWj by christo_pher (@christo_pher) on CodePen

  • Like 1
Link to comment
Share on other sites

Hm, if I understand your goal correctly, you could do something like:

var vars = {autoAlpha:0}; //all your regular, non-conditional stuff
if (yourCondition) {
    vars.xPercent = 25;
} else {
    vars.yPercent = 25;
}
TweenMax.to(element, 2, vars);

 

Or if you want to be concise/fancy:

vars[yourCondition ? "xPercent" : "yPercent"] = 25;

 

Does that help?

  • Like 5
Link to comment
Share on other sites

Yes, that helps. Thanks Jack!

 

You just called the property name on the fly. That was to simple. I did not think of that, obviously.

 

The purpose is create a timeline animation function that can be updated from whatever direction you want.  Codepen has been updated and gives an idea of my goal.

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