MadG Posted November 10, 2021 Share Posted November 10, 2021 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 More sharing options...
PointC Posted November 10, 2021 Share Posted November 10, 2021 I increased the duration and max x value a bit, but this should point you in the right direction. See the Pen fef3a5cf1dd3188f6ea93e052eb015ac by PointC (@PointC) on CodePen More info: https://greensock.com/docs/v3/GSAP/UtilityMethods/random() Happy tweening. 2 Link to comment Share on other sites More sharing options...
MadG Posted November 10, 2021 Author Share Posted November 10, 2021 Perfect! Thank you so much. 1 Link to comment Share on other sites More sharing options...
PointC Posted November 10, 2021 Share Posted November 10, 2021 Happy to help. Thanks for being a Club member. We really appreciate the support. 🙌 1 Link to comment Share on other sites More sharing options...
MadG Posted November 10, 2021 Author Share Posted November 10, 2021 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 More sharing options...
Solution PointC Posted November 10, 2021 Solution Share Posted November 10, 2021 I think I'd probably put it into a function that called itself after each iteration. Maybe something like this. See the Pen 8a208b01227fead3d30916074ca3a1a5 by PointC (@PointC) on CodePen Happy tweening. 1 Link to comment Share on other sites More sharing options...
GreenSock Posted November 10, 2021 Share Posted November 10, 2021 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. 1 Link to comment Share on other sites More sharing options...
PointC Posted November 10, 2021 Share Posted November 10, 2021 3 minutes ago, GreenSock said: Very minor thing: Ha! You're right. No idea why I wrote it like that. 🤷♂️ 1 Link to comment Share on other sites More sharing options...
MadG Posted November 10, 2021 Author Share Posted November 10, 2021 Perfect. Thank y'all. 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