Skip to content

Instantly share code, notes, and snippets.

@uto-usui
Created February 5, 2020 05:41
Show Gist options
  • Save uto-usui/a53cbb9de6526ea8b288835787f8521b to your computer and use it in GitHub Desktop.
Save uto-usui/a53cbb9de6526ea8b288835787f8521b to your computer and use it in GitHub Desktop.
Creating and setting CSS variables
const SetVar = ({propertyName, value, el, pre = 'my'}) => {
if (!el) {
document.documentElement.style.setProperty(`--${pre}-${propertyName}`, value)
} else {
el.style.setProperty(`--${pre}-${propertyName}`, value)
}
}
export default SetVar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment