Jump to content
Search Community

Pausing timeline when complete

hallibus 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

Hey guys,

 

I want to pause the timeline when it's completed.

 

tl = new TimelineMax({repeat: -1, paused: true});
    
    tl
        .to(dummy, 0.5, {x: '+=60', ease:Power3.easeOut}, 0.5)
        .addPause()
        .to(dummy, 0.5, {x: '-=60', ease:Power3.easeOut}, 1.5)
        .addPause();

 

The first addPause() works, the one at the end doesn't effect the timeline at all.

 

The timeline is paused on load, a click on a button starts it. It pauses on the first addPause, a buttons starts it again but it doesn't pause on the last addPause.

 

I hope it's somehow clear what I'm trying to achieve :)

 

I'm thankful for any help.

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

Link to comment
Share on other sites

Okay I don't know if this is the right way to do it, but I solved the problem via a simple function:

 

function pauseLeft() {
    tl.pause();
}

var dummy = document.getElementById('dummy');
    
    tl = new TimelineMax({repeat: -1, paused: true});
    
    tl
        .to(dummy, 0.5, {x: '+=60', ease:Power3.easeOut, onComplete:pauseLeft}, 0.5)
        .to(dummy, 0.5, {x: '-=60', ease:Power3.easeOut, onComplete:pauseLeft}, 1.5);

 

 

Thanks anyway :)

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