diff --git a/03 - CSS Variables/index-START.html b/03 - CSS Variables/index-START.html index 8a4f0d556e..125e199a04 100644 --- a/03 - CSS Variables/index-START.html +++ b/03 - CSS Variables/index-START.html @@ -21,6 +21,21 @@

Update CSS Variables with JS

- + diff --git a/03 - CSS Variables/script.js b/03 - CSS Variables/script.js new file mode 100644 index 0000000000..75d86d40fd --- /dev/null +++ b/03 - CSS Variables/script.js @@ -0,0 +1,11 @@ +const inputs = document.querySelectorAll('.controls input'); + +const handleUpdate = (e) => { + const suffix = e.target.dataset.sizing || ''; + const name = e.target.name; + const value = e.target.value; + document.documentElement.style.setProperty(`--${name}`, value + suffix); +}; + +inputs.forEach(input => input.addEventListener('change', handleUpdate)); +inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));