From b67600415d5d3cafd8220a64cd8a209991bf9bc1 Mon Sep 17 00:00:00 2001 From: ASAP Date: Sat, 21 Oct 2017 18:58:11 -0400 Subject: [PATCH] Completed Day 03 --- 03 - CSS Variables/index-START.html | 18 ++++++++++++++++-- 03 - CSS Variables/script.js | 11 +++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 03 - CSS Variables/script.js 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));