Jump to content
GreenSock

Sascha Fincher

dynamic property names

Recommended Posts

Hi everyone,

 

I am working on a color theme switcher at the moment, that is completely based on CSS custom properties. Normally I would tween those CSS variables like this:

GSAP.to(element, {
'--color-text': '#000'
})

 

My problem is that the properties I am tweening will always be passed as variable to my color manager. E.g.

function({key, color}){
  GSAP.to(element, {
    key: color // key will contain a string with a custom property
  })
}

I am sure I am missing something very basic, but cannot find a solution. Is the dynamic "creation" of a property from a string possible at all? Any hints would be appreciated.

Link to comment
Share on other sites

Yes, that was it. Thank you very much!

I did not think of the fact that the GSAP properties simply are object keys 🤦‍♂️

  • Like 2
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.
×