celli Posted January 17, 2020 Share Posted January 17, 2020 I am trying to use the helper function to pull a random element from an array that's not the PREVIOUS one that was pulled. I can't seem to figure out how to implement it into my gsap timeline. I tried referencing the function 'getRandomFrom' and then inserting my array just like using the random function, but I can't seem to get it work. Any help is appreciated. See the Pen MWYqXrr by celli (@celli) on CodePen Link to comment Share on other sites More sharing options...
ZachSaucier Posted January 17, 2020 Share Posted January 17, 2020 Hey celli. You need to call the function with the array as a parameter, so I recommend that you use an arrow function: const colors = ["#15c1e0", "#eebe19", "#a529c0", "#1e74dd"]; gsap.to(".box", {backgroundColor: () => getRandomFrom(colors), ...}); See the Pen KKwGgEd?editors=0010 by GreenSock (@GreenSock) on CodePen 2 Link to comment Share on other sites More sharing options...
celli Posted January 17, 2020 Author Share Posted January 17, 2020 Thanks Zach ! and apologies for the basic question, I should have figured that part out. Link to comment Share on other sites More sharing options...
ZachSaucier Posted January 17, 2020 Share Posted January 17, 2020 No problem at all! Things like that can be tricky. They're only simple if you know the answer 2 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