Jump to content


dynamic timeline position

Go to solution Solved by GreenSock,

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 wondering if there is a way to put tl.add() command into a loop to have cascade start of animation like this:

var abc = {
 xyz: function (obj) {
  var tl = new TimelineMax();
  tl.fromTo(obj, 3, { opacity: 0 }, { opacity: 1 })
  return tl

var tl = new TimelineMax();

DOMS.each(function (index) {
   tl.add(abc.xyz(DOMS[index]), "+=" + index) 
} )

Consider DOMs as array of any DOM objects.


However this approach doesnt work.

Same effect may be achieved with this:

   tl.add(abc.xyz(DOMS[0]), "+=0")    
   tl.add(abc.xyz(DOMS[1]), "+=1")    
   tl.add(abc.xyz(DOMS[2]), "+=2") 
But i am searching for more dynamic way depending on length of DOMS array. Is that possible to have time position dynamically set?
I do not post codepen, i hope it is obvious what is the problem here :)
Link to comment
Share on other sites

  • Solution

Wouldn't it just be:

var stagger = 0.1; //seconds between start times
DOMS.each(function(index) {
   tl.add(abc.xyz(DOMS[index]), index * stagger);

Also, are you familiar with the staggerTo()/staggerFrom()/staggerFromTo() methods? For example: https://greensock.com/docs/#/HTML5/GSAP/TimelineLite/staggerTo/

  • Like 1
Link to comment
Share on other sites

Hi Jack. Thank you for fast reply. Stagger wouldnt apply in my case because stagger accepts dom objects instead of functions, however my approach from first post wasnt working because of my error - your listing shows it works and i coded it on codepen and it magically worked - then i studied my case and found simple human error. So thank you and consider it solved




Dummy Kalreg... dummy Kalreg... 

  • Like 1
Link to comment
Share on other sites

Ha ha. No worries. Glad you figured it out. Thanks for letting us know. 

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.