Last active
March 25, 2020 16:21
-
-
Save monbang/063dd1b38c5924f90aedfdc69719e408 to your computer and use it in GitHub Desktop.
js-update css variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const inputs = document.querySelectorAll('.controls input'); | |
function handleUpdate() { | |
const suffix = this.dataset.sizing || ''; // data-sizing='something' | |
document.documentElement.style.setProperty(`--${this.name}`, this.value); // css variable | |
} | |
inputs.forEach(input => input.addEventListener('change', handleUpdate)); | |
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment