Jump to content
Search Community

TweenMax.staggerTo() array item index

usheeen 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

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 2 years later...
  • 9 months later...

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