Pause or Resume an Animation by Checking isActive with GreenSock

John Lindquist
InstructorJohn Lindquist

Share this video with your friends

Send Tweet
Published 4 years ago
Updated 2 years ago

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

Instructor: [00:00] 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.

[00:09] 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.

[00:25] 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.

[00:51] 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.