Jump to content
GreenSock

cezaleo

Animation interruption, then resetting that timeline.

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

I have two timelines.. tl1, tl2 for demonstration purposes.

 

tl1 starts when the dom is ready. tl2 starts via button click. There is another button that reverses everything to where tl1 starts.

 

The problem I have is that if the button that starts tl2 is clicked before tl1 is finished, then someone clicks the button that reverses the timelines to the start of tl1, then tl1 is reversed to the point where the interruption happened.

 

How can I tell the button that reverses everything back to tl1 to go all the way back to zero?

Link to comment
Share on other sites

Hi,
 
You could use the time() and tweenFromTo().

 

With the time() method you'll get the current time of the timeline, you store that in a variable. Then using the tweenFromTo() method you'll tell the function to tween the timeline from the time stored in that variable to zero, like this:

var button = $("button#buttonID"),
    tl1 = new TimeilneMax(),
    tl2 = new TimelineMax(),
    tl1Time;

button.click(function()
{
    tl1.pause();
    tl1Time = tl1.time();
    tl1.tweenFromTo(tl1Time, 0);
    tl2.reverse();
});

Take a look at the reference docs:

 

time() method

tweenFromTo() method

exportRoot() method

 

Another choice would be to use the exportRoot() method, put everything in a parent timeline and reverse that timeline.

 

Anyway I'm pretty sure that you're dealing with an overwrite issue and if that's the case I'm not sure if anything I've suggested will work as expected; if it doesn't, there's any chance you could set up a live sample or a fiddle or codepen in order to take a better look?.

 

Hope this helps,

Cheers,

Rodrigo.

  • Like 1
Link to comment
Share on other sites

I have to ditto rodrigo's assumption that this is an overwrite issue. When you try to perform 2 tweens at the same time that effect the same properties of the same object the default behavior is that the newest tween will overwrite the parts of the older tween that overlap. The overwritten tweens get killed and destroyed never to be heard from again.

 

You can read more about various overwrite modes in the TweenLite docs: http://api.greensock.com/js/com/greensock/TweenLite.html

 

Also, a very simple codepen example would help us better recommend a suitable solution.

You can just fork something like this

See the Pen 7246d0e3ebfe775eea901b27bcf0a361%25C2 by GreenSock (@GreenSock) on CodePen

">

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