Jump to content
GreenSock

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

Change animation variables from each loop iteration

Go to solution Solved by OSUblake,

Recommended Posts

Trying to change background color to different color for each loop iteration using onRepeat callback.

 

It doesn't work. How can I acheve this? Thanks.

 

let R, G, B, dur;

const setVars = () => {
  R = Math.floor((Math.random() * 255)),
    G = Math.floor((Math.random() * 255)),
    B = Math.floor((Math.random() * 255)),
    dur = Math.floor((Math.random() * 4));
}

const getColor = () => {
  setVars();
  return `rgb(${R}, ${G}, ${B})`;
};

setVars();

TweenMax.to(".colores", {
  duration: dur,
  backgroundColor: getColor,
  repeat: -1,
  onRepeat: getColor(),
});

 

See the Pen RwpzzPJ by aitormendez (@aitormendez) on CodePen

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.
×