Jump to content
Search Community

Timeline animation pause / resume with conditionals not working

Demorus 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

I am having trouble getting my timeline animation to pause and resume with my conditional statements. The script below is in a seperate script tag

 

 if ( $(".ball").hasClass( "active" ) ) {        
      textAnimation.pause();
    }
       else {
 textAnimation.resume();
     }

 

Why is this happening? there are no errors and the animation name is written as it should. I also read the documentation and I am using pause() and resume() correctly.

Link to comment
Share on other sites

Hello Demorus, and Welcome to the GreenSock Forum!

 

You could try and use the GSAP isActive() method:

:

.isActive( ) : Boolean

Indicates whether or not the animation is currently active (meaning the virtual playhead is actively moving across this instance's time span and it is not paused, nor are any of its ancestor timelines).

:

isActive() .. Indicates whether or not the animation is currently active (meaning the virtual playhead is actively moving across this instance's time span and it is not paused, nor are any of its ancestor timelines). So for example, if a tween is in the middle of tweening, it's active, but after it is finished (or before it begins), it is not active. If it is paused or if it is placed inside of a timeline that's paused (or if any of its ancestor timelines are paused), isActive() will return false. If the playhead is directly on top of the animation's start time (even if it hasn't rendered quite yet), that counts as "active".

You may also check the progress() or totalProgress(), but those don't take into consideration the paused state or the position of the parent timeline's playhead.

 

With your code it would look like this:

:

// tl represents your timeline instance variable
if (tl.isActive()=== true) {        
      textAnimation.pause();
} else {
     textAnimation.resume();
}

:

The tl instance above would be the current timeline instance you are checking for isActive()

 

Hope that helps :)

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