Jump to content
Search Community

Child TimelineMax within a Parent TimelineMax

fiatuno 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

Hi 

 

Wishing you all a Happy 2019.  

 

I have an animation requirement where I have a TimelineMax instance and number of TweenMax instances added to it and some of these TweenMax instances (not all) need to be repeated for number of times. So my question is can I create TimelineMax instances and add repeating instances to it and add these repeating TimelineMax  instances to the main TimelineMax instance will it work.

 

 

Example:

 

// somewhere globally create main 

var mainTimeline = new TimelineMax({repeat: false, paused: false});

 

//later on we loop through an array of objects 

 

If (obj.repeat){

     var tlr = new TimelineMax({repat:99, yoyo:true, paused: false});

     tlr.add(TweenMax.to(obj, duration, { x:x, 

                                                                y:y,

                                                               ease:Quint.easeOut,

                                                               onUpdate:updateDraw,         

                                                               overwrite: "none" }));
}else{

   //add TweenMax instances to mainTimeline

   mainTimeline.add(TweenMax.to(obj, duration, { x:x, 

                                                                y:y,

                                                               ease:Quint.easeOut,

                                                               onUpdate:updateDraw,         

                                                               overwrite: "none" }));

}
mainTimeline.add(
tlr, self.getDelay();

 

//end code

 

 

 

Thanks in advance

 

Link to comment
Share on other sites

I just found an interesting behavior as per the above code if I set repeat to the mainTimeline then it will repeat.  But if the main timeline is not repeating and if add another timeline (with repeat:99) to the mainTimeline then this second timeline will not repeat.   

Link to comment
Share on other sites

You can certainly add repeating timelines (or tweens) to any timeline. No problem at all. Nest things as deeply as you want. 

 

I had a hard time understanding what you were describing with the "interesting behavior" - can you post a codepen demo? 

 

Your sample code had several mistakes. Like you were adding tlr to mainTimeline regardless, but you were only populating that variable inside on condition, so that code would break in the other condition. And I'm not sure what "self" refers to, but there's no getDelay() method in any GSAP stuff. 

 

Keep in mind that if you've got a child animation that repeats 99 times, its parent will wait for ALL of those to finish before it repeats. See what I mean? 

 

If you still need some help, just post a codepen demo and we'd be happy to take a peek. 

 

Happy tweening!

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