Share Posted October 21, 2016 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 More sharing options...
Share Posted October 21, 2016 Hello venn Take a look at this codepen by Blake. See the Pen YWjARB?editors=0010 by osublake (@osublake) on CodePen You will see a function called random in there. You can get an idea of one way how to randomize your values. 2 Link to comment Share on other sites More sharing options...
Share Posted October 21, 2016 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. 2 Link to comment Share on other sites More sharing options...
Author Share Posted October 22, 2016 Oh wow, some clever ways to do tricks here! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now