Jump to content
Search Community

Possible to run onComplete function ONLY after timeline has been played in reverse?

kbeats test
Moderator Tag

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, I'm using GSAP in an external javascript file that I'm using to control navigation buttons in Adobe Captivate course. Long story short - I'm wondering if there is a way I can have a function run after my timeline finishes it's animation, but ONLY after the timeline has been played in reverse? 

 

I have a timeline for each button (back and next), and it plays when the user clicks on the button, then reverse when they let the mouse up. I'd like after they let the mouse up for Captivate project to go to the next page - but the way I'm doing this now, putting the function to go the next page right after the tl.reverse(); call , it happens before the animation has time to complete. (In my codepen I'm changing the color of one of my buttons, since it's not in Captivate). 

 

I know I could accomplish this by having a separate timeline for each mouseup and mousedown event listeners - but I'm trying to consolidate my code. Thanks for any help and advice! 

See the Pen QWWweRw by kbeats (@kbeats) on CodePen

Link to comment
Share on other sites

Hello @kbeats and welcome to the GreenSock forum!

 

For an onComplete reverse please use the onReverseComplete special callback.

 

Quote
onReverseComplete:  Function - A function that should be called when the animation has reached its beginning again from the reverse direction. For example, if reverse() is called the tween will move back towards its beginning and when itstime reaches 0, onReverseComplete will be called. This can also happen if the animation is placed in a TimelineLite or TimelineMax instance that gets reversed and plays the animation backwards to (or past) the beginning.
 
onReverseCompleteParams:  Array - An Array of parameters to pass the onReverseComplete function. For example, TweenMax.to(mc, 1, {x:100, onReverseComplete:myFunction, onReverseCompleteParams:[mc, "param2"]}); To self-reference the tween instance itself in one of the parameters, use "{self}", like: onReverseCompleteParams:["{self}", "param2"]
 
onReverseCompleteScope: Object - Defines the scope of the onReverseComplete function (what "this" refers to inside that function).

 

Resources:

TweenMax: https://greensock.com/docs/v2/TweenMax/static.to()  
(Find the Parameters sections and click the Show More button)

 

Happy Tweening :)

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