Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
anteksiler

Conditions inside Timeline

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

Hi everyone, as I get better in GSAP, my needs also increase and everyone on the forums have been very helpful.

 

What I want to do is, check for a condition, lets say if element.length > 0, and add tween inside the timeline. What is the best way of doing this?

 

 

Link to comment
Share on other sites

Hello anteksiler,

 

You can try and use the add() method.. here are some common uses for add():

 

http://greensock.com/docs/#/HTML5/GSAP/TimelineMax/add/

:

//add a tween to the end of the timeline
 tl.add( TweenLite.to(element, 2, {left:100}) );
 
 //add a callback at 1.5 seconds
 tl.add(func, 1.5); 
 
 //add a label 2 seconds after the end of the timeline (with a gap of 2 seconds)
 tl.add("myLabel", "+=2");
 
 //add another timeline at "myLabel"
 tl.add(otherTimeline, "myLabel"); 
 
 //add an array of tweens 2 seconds after "myLabel"
 tl.add([tween1, tween2, tween3], "myLabel+=2"); 
 
 //add an array of tweens so that they are sequenced one-after-the-other with 0.5 seconds inbetween them, starting 2 seconds after the end of the timeline
 tl.add([tween1, tween2, tween3], "+=2", "sequence", 0.5);

:

Then a possible use is:

:

// create timelines
 var tl = new TimelineMax(),
     otherTimeline  = new TimelineMax();

// other tweens and timelines ...

//add otherTimeline instance in tl instance at "myLabel"
 tl.add(otherTimeline, "myLabel"); 

// other tweens and timelines ...

:

:Resources:

add()

TweenMax

TimelineMax

 

I hope this helps :)

  • Like 1
Link to comment
Share on other sites

Hi anteksiler  :)

 

you can do something like this :

var tl = new TimelineMax({paused:true});

if ( elements.length > 0 ) { tl.to(elements,5,{......}) };
/* 
as Jonathan said , you can use labels / gaps,delays for your tweens :

var tl = new TimelineMax({paused:true});
    tl.add("youLabel", "+=2")

if ( elements.length > 0 ) { tl.to(elements,5,{......},"youLabel") };
*/
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.
×