Jump to content
GreenSock

macguffin

TimelineMax not firing TweenLite onStart function when repeating

Recommended Posts

Great topic title I know, sorry about that.

 

Hi I'm trying to build a TimelineMax animation dynamically by adding TweenLites which is working fine.

As part of the code I need a function to be called when each of the TweenLite animations start. I'm doing this by calling onStart:. Again this works fine.

 

I am repeating the timeline as I want to play it backwards which again is visually working as expected. I don't however seem to be able to get the onStart function to call when the TimelineMax animation is in reverse.

 

In case this description makes no sense I have a codepen demo, you can see that the count is only increasing whilst the animation is playing forwards. 

 

I've also tried TimelineMax.reverse but this also only calles the onStart when going forwards. 

 

I'm sure there is an easy way to achieve this can anyone point me in the right direction.

 

Cheers

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

Link to comment
Share on other sites

Thanks for the demo, very helpful.

 

onStart only fires when the tween starts playing from a time of 0 and moves forward.

If you want a callback to fire whenever the playhead reaches the beginning of a tween, regardless of direction, I would suggest adding a separate callback directly to the timeline at the same time the tween is added like so:

 

while (i--) {
  tl.call(updateCount)
    .to('#redBox', 0.05, {x: "+=10"});
}

function updateCount() {
  _count++;
  console.log(_count)
}

see it here: http://codepen.io/GreenSock/pen/EaXRPw?editors=001

 

Does that work for you?

  • Like 1
Link to comment
Share on other sites

Of course so simple when you know how :)

 

That will work just fine for what I need, I knew there would be a way around it as you guys seems to have thought of most things.

 

Thanks very much for such a speedy response.

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