Jump to content
Search Community

Check if animation is active

mark772 test
Moderator Tag

Go to solution Solved by OSUblake,

Recommended Posts

  • Solution
11 minutes ago, akapowl said:

There's probably a more elegant way, but something like this would work:

 

You can combine your undefined and isActive check like this.

if (tween1 && tween1.isActive()) {
  ...
}

 

Another way is to use gsap.getTweensOf(). If the length is 0, that means there are no active tweens on those targets, which will evaluate to false. Any other length value will be true, which means there are active animations.

 

if (gsap.getTweensOf([cube.rotation, cube1.rotation]).length) {
  ...
}

 

  • Like 2
Link to comment
Share on other sites

6 minutes ago, OSUblake said:

You can combine your undefined and isActive check like this.

 

I tried that before and it's throwing an error

 

See the Pen fc60f76a874e2de6e05f33b89cd1bbbb by akapowl (@akapowl) on CodePen

 

 

 

This will of course still be shorter than what I have in my reply above:

 

if (typeof tween1 !== 'undefined' && tween1.isActive()) {
	...
}

 

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