Jump to content
Search Community

TweenMax.staggerTo() array item index

usheeen
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

Posted

Is there a way to reference the item's index from the vars. For example:

TweenMax.staggerFrom($items, 1, {
  y: -100 * itemIndex
}, 0.5);

I can calculate the index like this: $items.index(this.target) but it seems like it's something that TweenMax should expose directly.

 

  • Like 1
Posted

The stagger methods require that all animated properties are the same for each element that is being animated. The important focus of these methods is the ability to conveniently offset the start times. If you need random or incremented values to animate from, the solution is to use a loop

$(".box").each(function(index, element){
  TweenLite.from(element, 0.5, {x:(index+1) * 200, opacity:0, delay: index * 0.2})
})

http://codepen.io/GreenSock/pen/LgJEe?editors=001

 

In theory, what you propose is a nice idea, however finding a practical implementation is non-trivial.

My guess is that any valid solution is going to be just as much code as the loop or perhaps far more cryptic. 

 

We're certainly open to ideas though. Keep 'em coming.

  • Like 3
Posted

Thanks for the info Carl.

 

I just thought it might be something I had overlooked in the documentation.

Your solution is fine, I'm happy to loop like I did in the days before TweenMax.staggerTo()

  • 2 years later...
Posted

You need to add a ModifiersPlugin

  TweenMax.staggerFrom('.box', 1, {
    y: function(index) { return (index+1) * -100;}
  }, 0.5);
  • 9 months later...
Ranjeet Sengar
Posted

You may use cycle property  available in the staggerFrom() method in TweenMax

 

 

TweenMax.staggerFrom('.box', 1, {
    cycle:{
      y: function(index) { return (index+1) * -100;}
    }
  }, 0.5);

 

  • Like 1

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...