Jump to content
GreenSock

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

Flexible duration of the animation

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

It's m first post here so i'd like to say hello. I have been learning to use greensock mostly for banners and it's awesome :) I wonder if I can set the animation time based on labels instead of duration in seconds.

 

 

See the Pen bKyaab by plastois (@plastois) on CodePen

 

I want the pink box to start to animate on the "startPink" label and end up on the "endPink" label(start with blue boxes and end with yellow) without setting duration in seconds, so that I can freely change the times of the animation or the position of the labels.

 

But there are a few problems that I hope you can help me solve:

1)Is there an option to do this within one timeline?

2) I set delay equal to "labelTimeSTART" time but it start before previous animation ends. Why?

 

I could not find a solution, so I apologize in advance if the solution is in another post. And sorry for the poor English :)

See the Pen bKyaab by plastois (@plastois) on CodePen

Link to post
Share on other sites

Hi Plastois,

 

Welcome to the GreenSock forums.

 

Glad to see that you are doing so well with GSAP!

 

I want to commend you on providing such an excellent demo that so clearly illustrated the issue you were facing. Its such a big help! You wouldn't be believe how many there are that don't make the effort. Great job!

 

You already did the hard work of dynamically figuring out the start time and durations based on the positions of your labels. The good news is you can use these values in a single tween without creating a new timeline as long as you add that tween AFTER you have put your other animations in.

 

In the code below I'm using your dynamic values for the duration and position parameter

 

tl.from(".pink", labelTimeEND - labelTimeSTART, {scaleX: 0.001, ease:Linear.easeNone}, labelTimeSTART)

 

See the Pen yEWQLx?editors=0010 by GreenSock (@GreenSock) on CodePen

 

I gave the tween a Linear ease just so that its easier to see that it ends exactly when it should.

 

----

 

As for your second question

 

 

2) I set delay equal to "labelTimeSTART" time but it start before previous animation ends. Why?

 

It seems that the delay that you set on the timeline "appears" to be ignored when you dynamically changed the duration of tl2

var tl2 = new TimelineLite({
  delay: labelTimeSTART //4.1
});


tl2
.from(".pink", 10, {scaleX: 0.001})
.duration( labelTimeEND - labelTimeSTART );

 

in your example if you remove the duration() line the delay works fine. I will look to see if this is a bug, or just a side-effect due to necessary logic in the engine.

 

Thanks again for the awesome demo, and welcome aboard!

 

Let us know if you need any more help with this.

 

 

 

 

 

 

 

  • Like 4
  • Thanks 1
Link to post
Share on other sites

Wow, thank you for such a quick response. This is exactly the solution that I wanted to achieve! I did not think that one TimelineLite can be called twice without overwriting the previous one! For now, I know everything that I need and I am going to take an animation along the SVG path :) 

 

Thank you for this very nice welcome and support. It is not often that such a positive community is found.

  • Like 2
  • Thanks 1
Link to post
Share on other sites

No problem. Happy to help. Very glad we could find a suitable solution for you.

 

BTW I can confirm that when you change the duration() of a timeline it will also impact the delay. You could make valid arguments that it should or shouldn't do this, but at some point it made sense that it should. Just want you to know that its not a bug.

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

×