Jump to content
Search Community

Change animation variables from each loop iteration

Aitor test
Moderator Tag

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.
×
×
  • Create New...