Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
MadG

Animating Arrays - Giving each item a different random value

Go to solution Solved by PointC,

Recommended Posts

Pretty simple question, just one I can't figure out an answer to! See codepen above. Rather than having all 10 boxes moving left and right according to the same random number, I want each of them to have a different random left and right value. How can I accomplish this? 

See the Pen vYJamoV by kslaton (@kslaton) on CodePen

Link to comment
Share on other sites

Perfect! Thank you so much. 

  • Like 1
Link to comment
Share on other sites

Happy to help. Thanks for being a Club member. We really appreciate the support. 🙌 

  • Like 1
Link to comment
Share on other sites

No problem at all, we love us some GSAP here at our agency. 

 

I do actually have one more question. Say I wanted the random bounds to increase on each repeat. So first go round they go random(0,500), then next round random(0, 750), etc etc. Is there a way i can accomplish that?

Link to comment
Share on other sites

Nice job, @PointC. That's a great solution. 🎉

 

Very minor thing: 

newMax = newMax < 600 ? (newMax += 100) : (newMax = 100);

Should probably be: 

newMax = newMax < 600 ? newMax + 100 : 100;

 

I also thought of a different (not necessarily better) approach: 

See the Pen c784d28b84400ce17949fcd17d8a4bc6 by GreenSock (@GreenSock) on CodePen

 

But honestly, my first instinct was to go with precisely the technique @PointC suggested. 

  • Like 1
Link to comment
Share on other sites

3 minutes ago, GreenSock said:

Very minor thing: 

Ha! You're right. No idea why I wrote it like that. 🤷‍♂️

  • Like 1
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.
×