Jump to content
GreenSock

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

Callback duration in a timeline

Recommended Posts

Hi,

 

while developing a responsive GSAP animation, I came across these problems. Please refer to the codepen link for my code.

 

* when resetting the timeline to 0, why aren't the elements properly reset to their initial position? (line 28 in js)

* after the first red box has tweened, the timeline will pause until the green box is clicked. However why is the extra delay needed for the second callback to not execute when resizing the browser at that time? (line 38 in js). The only thing I can think of is that a function does not add any duration to the timeline, resulting in multiple subsequent added callbacks to be executed at the exact same time in the timeline (which makes kind of sense..), am I correct?

See the Pen QONGME by anon (@anon) on CodePen

Link to comment
Share on other sites

Its a little tricky but here goes...

 

A from() tween animates from a value you specify to an existing value.

When your app first loads x is 0.

You create an x tween from width-100

Lets say when the app loads the width is 800

The first from() tween animates x from 700 to 0.

At a progress(0) x is 700.

 

Let's say that shortly after the animation starts x is 600 and you change the browser size to 400.

When you set the progress() back to 0, x goes back to 700 NOT 0. 

So x is 700 when you clear() the timeline and rebuild it.

Remember the browser size is now 400

Your from() tween now tweens from 300 to 700

 

The take away here, changing the progress() to 0 does not clear properties, it goes back to the values that were recorded at a time of 0. 

 

When you resize the browser the resize() events fire crazy fast, so you are repeatedly creating new from() tweens that have start values that are extremely close to the end (existing) values.

 

using the set()s as you did to clearProps is fine, or you can set the from and to values using fromTo()

Open the demo below in a new window and resize as it plays. It should give the results you want

 

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

 

As for your second question, yes, function calls don't take up any time. if you do to call()s at the same time (with no position offset) they will fire at the same time.. in your case cancelling each other out.

 

 

 

 

 

 

 

 

 

 

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