Jump to content
Search Community

Using .isActive() with a tween-function

Nanetten 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

Basically I have two "tweens" stored as functions and I want to use isActive() to know when to trigger the next animation, this is my first time using GSAP so I feel a bit lost.  I read the documentation and checked out this 

See the Pen Pwzomo by GreenSock (@GreenSock) on CodePen

 but I couldnt figure it out.

 

Here is what I mean (or go to line 8 and 23 in my codepen) :

 

 var toCenter = function(element) { 
    TweenLite.to( element, 0.5, {opacity:1, yPercent: -50,  delay: 0.5});
  }
 
 if (!toCenter(element).isActive()) {
   // code
 }

 

 

Thanks for your help.

 

 

See the Pen dZdWrm by Nanetten (@Nanetten) on CodePen

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums,

 

Thanks for the demos. For stuff like this it really helps to simplify things as much as possible. I got a bit lost in everything going on with the scroll-driven code and conditional logic.

 

I simplified things to show that you can still create a tween in a function by returning it to a global var

 

See the Pen gXvZQW?editors=0010 by GreenSock (@GreenSock) on CodePen

 

You could also do something like

var myTween;

var myFunction = function(element){
  myTween = TweenLite.to(element, 2, {x:200})
}

//later

if(myTween.isActive());

 

  • Like 4
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...