Search code examples
javascriptgsap

GSAP staggerFrom negative delay


Question:

I am wondering if there is a way to add a negative delay to the staggerFrom / staggerTo functions in greensock?

Problem:

I have animation is running too long for my liking. It would be great if my staggered animations could happen as the previous animations are playing to cut down the duration.

Example:

I have put together this codepen to illustrate what I am after: http://codepen.io/nickspiel/pen/LpepvQ?editors=001

You can see in the codepen that I have used negative delays on the basic from timeline functions but this doesn't work for the staggerForm function as the delay parameter is used to delay each element of the jquery collection.


Solution

  • I asked this same question on the Greensock GitHub repo and had the following response:

    Absolutely - that's already baked in. I'm not sure if you're using TweenMax or one of the timeline classes, so I'll show you both:

    TweenMax.staggerTo(elements, 1, {x:100, delay:2}, 0.01);
    
    // - OR -
    
    var tl = new TimelineLite();
    tl.staggerTo(elements, 1, {x:100, delay:2}, 0.01);
    
    // - OR -
    
    var tl = new TimelineLite(); 
    tl.staggerTo(elements, 1, {x:100}, 0.01, "label+=3");
    

    In my case the last option worked flawlessly.