Jump to content


Animate Attribute Based On External Variable

Recommended Posts

In the codepen, the spinning box should swap colors every iteration. I used `onComplete` to call a function that moves the color index further, and the tween should take the current index color from the array at the top.

This... well... doesn't work as I expect it to, but I couldn't quite find a way to do this.

Checking the colorIndex in the console after every spin shows that it doesn, in fact, change. But the Tween doesn't pick up the new value on the next spin. I wonder why, and I also wonder what the correct way is to do this.



I solved it myself by making background into a function, figuring that unlike the value, the function would be called every time.

However, this doesn't seem right, and I'd still like to know if there's a better way to do this!

See the Pen zYEqNRm by LarkRanger (@LarkRanger) on CodePen

Link to comment
Share on other sites

Well it still calls a function every single time, but it does look like it fits here.

Thanks though Cassie, you've been very helpful the past few days! :)

  • Like 1
Link to comment
Share on other sites

My pleasure mate! Happy to help. 🥳

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.