Pause or Resume an Animation by Checking isActive with GreenSock

John Lindquist
InstructorJohn Lindquist
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 4 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.

egghead
egghead
~ 8 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today