Jump to content
Search Community

How to play onComplete on timeline reverse

mk1 test
Moderator Tag

Go to solution Solved by mk1,

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

Hey, quick question.

 

How can I make this onComplete part work on main timeline reverse?

.to(imessagewrapper, 0.4, {autoAlpha: 1, ease: Back.easeOut.config(1.7), onComplete: function () {
            imessage_tl.play();
        }}, "S22")

I don't want to launch this timeline in .add() or as a tween, as this will ruin my timeline behaviour.

Link to comment
Share on other sites

Update, but still not working

.to(imessagewrapper, 0.4, {autoAlpha: 1, ease: Back.easeOut.config(1.7), onComplete: function () {
            imessage_tl.play();
            console.log("Trying to play");
        }, onReverseComplete: function () {
            imessage_tl.play();
            console.log("Trying to play on reverse");
        }}, "S22")

Here I found something about onREverse call https://greensock.com/forums/topic/9499-onreverse/?hl=onreverse#entry38487

 

but it's not listed here:

 

https://ihatetomatoes.net/wp-content/uploads/2015/08/GreenSock-Cheatsheet-2.pdf

Link to comment
Share on other sites

  • Solution

Okay, problem solved, it's still hard for me to picture how the code is executed on reverse actions :), need more exp :D

 

Here's my solution:

.to(imessagewrapper, 0.4, {autoAlpha: 1, ease: Back.easeOut.config(1.7), onComplete: function () {
            imessage_tl.play();
            console.log("Trying to play");
        }}, "S22")
        .add("S2end")
        .addPause()

        .to('#innerDotWrapper', 0.4, {autoAlpha: 0, height: 0, marginBottom: "0px", onComplete: function () {
            imessage_tl.pause(0);
            console.log("Pause");
        }, onReverseComplete: function () {
            imessage_tl.play();
            console.log("Trying to play on reverse");
        }}, "S3")

If someone was so nice and explain to me why my previous solution refused to work I will much appreciate it.

Link to comment
Share on other sites

It worked in the end, although I imagine you're still working on this as it kind of breaks if I change the window size. Lots of things misalign. 

 

Anyway, trying to read a whole website's worth of code is a no go. Too much to wade thru there mate, sorry.

 

However, I can give a punt as to why the first attempt did not work and the second did (at least I think it is why, only an example pen would set this matter to rest but it's a tad late here and I won't set one up at the moment... Soz...)

 

Here, you have two instances of .play() in the same timeline but notice you are not passing any arguments to the method.

.to(imessagewrapper, 0.4, {autoAlpha: 1, ease: Back.easeOut.config(1.7), onComplete: function () {
 imessage_tl.play();
 console.log("Trying to play");
}, onReverseComplete: function () {
 imessage_tl.play();
 console.log("Trying to play on reverse");
}}, "S22")

By default, the .play() method just continues playing from where the virtual playhead is until it reaches the end of that timeline. Once at the end, it doesn't really do anything. I think it is safe to say that by the time you get to the onReverseComplete() call the imessage_tl has finished playing and thus, nothing else would happen.

 

In your second attempt, you have a different setup that includes the following:

imessage_tl.pause(0);

That makes the virtual playhead jump back to the start of the timeline and so, when you later have the onReverseComplete() call, the imessage_tl plays from its beginning.

 

In order for the first setup to work, you would simply add a zero as a parameter into your .play() methods, like so:

.to(imessagewrapper, 0.4, {autoAlpha: 1, ease: Back.easeOut.config(1.7), onComplete: function () {
 imessage_tl.play(0);
 console.log("Trying to play");
}, onReverseComplete: function () {
 imessage_tl.play(0);
 console.log("Trying to play on reverse");
}}, "S22")

That way, every time that tween either completes playing or reversing, the imessage_tl is going to start right from the start, no matter where its virtual playhead is.

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