Skip to content

Commit c7568cd

Browse files
author
Jess Hines
committed
JDH: Finish wesbos#3
1 parent 61ae883 commit c7568cd

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

03 - CSS Variables/index-START.html

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
99

1010
<div class="controls">
1111
<label for="spacing">Spacing:</label>
12-
<input type="range" name="spacing" min="10" max="200" value="10" data-sizing="px">
12+
<input type="range" name="spacing" min="10" max="200" value="10" data-units="px">
1313

1414
<label for="blur">Blur:</label>
15-
<input type="range" name="blur" min="0" max="25" value="10" data-sizing="px">
15+
<input type="range" name="blur" min="0" max="25" value="10" data-units="px">
1616

1717
<label for="base">Base Color</label>
1818
<input type="color" name="base" value="#ffc600">
@@ -21,6 +21,20 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2121
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">
2222

2323
<style>
24+
:root {
25+
--base: #ffc600;
26+
--spacing: 10px;
27+
--blur: 10px;
28+
}
29+
30+
img {
31+
padding: var(--spacing);
32+
background-color: var(--base);
33+
filter: blur(var(--blur));
34+
}
35+
.hl {
36+
color: var(--base);
37+
}
2438

2539
/*
2640
misc styles, nothing to do with CSS variables
@@ -48,6 +62,16 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4862
</style>
4963

5064
<script>
65+
const inputs = document.querySelectorAll(
66+
'.controls input');
67+
68+
function handleUpdate() {
69+
const units = this.dataset.units || '';
70+
document.documentElement.style.setProperty(`--${this.name}`, `${this.value}${units}`);
71+
}
72+
73+
inputs.forEach(input => input.addEventListener('change', handleUpdate));
74+
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));
5175
</script>
5276

5377
</body>

0 commit comments

Comments
 (0)