Jump to content
Search Community

TweenMax.fromTo set vars

andyr test
Moderator Tag

Go to solution Solved by Rodrigo,

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

  • Solution

Hi,

 

For optimization reasons what you're trying to do is not possible. Basically when you create a GSAP instance the starting and end values of the properties being tweened are recorded in order to avoid continous read/write operations.

 

What I do when I face this type of scenarios is to create a function to create the fromTo instance again and use the instance's current progress to avoid restarting it, like this:

var tween = TweenMax.fromTo(element, time, {/*fromVars*/}, {/*toVars*/});

// the function, just pass the config object as arguments
function createTween(fromVars, toVars) {

  var currentProgress = tween.progress();

  tween.kill();

  tween = TweenMax.fromTo(element, time, {fromVars}, {toVars}).progress(currentProgress);
}

// later on your code call the function
createTween({x:0, y:0, rotationX:0},{x:100, y:100, rotationX:180});

Give that a try and let us know if you need anything else.

 

Rodrigo.

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