Jump to content
Search Community

Changing timeline settings on the fly

Learning test
Moderator Tag

Go to solution Solved by Carl,

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 guys,

 

Sorry, one last question today!

Is it possible to change the settings of tweens inside my timeline on the fly?

Like changing its duration or easing?

myTime = 10;
myEase = Expo.easeInOut;

myTimeline.to( $slide1, 2, { xPercent: -100, delay: myTime, ease: myEase } )
.to( $slide2, 2, { xPercent: -100, delay: myTime, ease: myEase } )
.to( $slide3, 2, { xPercent: -100, delay: myTime, ease: myEase } )

myButton.click(function() {
 myTime = 2;
 myEase = Expo.easeOut;
 myTimeline.play(0);
})
Link to comment
Share on other sites

  • Solution

Yes, but it can be a bit tricky. Most of the time we recommend that you just re-build your timeline if you want it to run a different way. 

 

Changing variables like myTime = 2 like you have now will have no impact on the tweens that are already created as they already recorded the values they need.

 

You would need to store a reference to the tween you want to modify and modify its properties directly.

 

Here is a demo that lets you change the duration() and startTime() of the tween that controls the orange div: 

http://codepen.io/GreenSock/pen/7e95e619423bcefb9dc8ea01a51c38ef?editors=0010

 

Let the demo play and notice that the green and orange divs start at same time and move at same speed.

Press buttons to change orange behavior.

 

If you have animations that you know you are going to want to change, I think its much better to create them the way you want them when you need them than worry about managing a bunch that you need to update.

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