Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Pause or Resume an Animation by Checking isActive with GreenSock

    John LindquistJohn Lindquist

    You often need to pause or resume an animation based on whether or not the current animation running. The isActive() getter returns a boolean that provides you with that information (the opposite information can be found with using the paused() getter).



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    Instructor: When I click on this box, it goes right, left, down, up. If I click again, nothing happened. Also, I can't interrupt it and tell it to stop the animation.

    First, I'm going to configure my timeline to repeat infinitely. I do that by saying repeat is -1. If I click now, you'll see it'll continue going around and around.

    Inside of my click handler, I can check when I click if timeline. is active. If it is active, I can say timeline.pause. If it's not active, I'll say timeline.resume. When I click, it'll start going and continue forever. I'll click and pause it and click and resume it.

    This current setup is possible because we start paused and we only resume when we click and it's inactive. Once it is active, we go back to that pause state. We're toggling between resuming and pausing, checking to see if the timeline is active.