Jump to content
GreenSock

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

Helper Function for Random

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

  • Like 2

Share this post


Link to post
Share on other sites

Thanks Zach ! and apologies for the basic question, I should have figured that part out.

Share this post


Link to post
Share on other sites

No problem at all! Things like that can be tricky. They're only simple if you know the answer :) 

  • Like 2

Share this post


Link to post
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.

×