Jump to content
Search Community

Randomize an array and stagger them.

venn test
Moderator Tag

Go to solution Solved by Jonathan,

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

What is the easiest way to always randomly shuffle all items in an array and then stagger them.



var items = [a, b, c, d, e]; <-- Random order everytime
TweenMax.staggerTo(items, 1, {opacity: 1}); 

1) I can first randomize my array by following this link


http://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array


 


Then only do my stagger effect.


 


2) Or can I use the new .cycle method in stagger. Will that be something I can leverage? Or any better/simpler ways?


Link to comment
Share on other sites

Your best bet is going to be creating a function that re-shuffles your array and then creates a new staggerTo() each time.

 

staggerTo() is a helper method that simply creates an Array of tweens with unique delays for each one. Once it runs its not like you can easily reference those tweens and say "oh you need to run in a different order". Technically you could go into the array of tweens that staggerTo() creates and manually update all of their delays and then tell them all to restart() again, but I don't think there is any benefit to that approach.

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