Skip to content

Commit 9ed8eb1

Browse files
committed
Completed exercise wesbos#3 of JS30.
1 parent 3241fa1 commit 9ed8eb1

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

03 - CSS Variables/index-START.html

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

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

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

1717
<label for="base">Base Color</label>
18-
<input id="base" type="color" name="base" value="#ffc600">
18+
<input id="base" type="color" name="base" value="#1354ff">
1919
</div>
2020

2121
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">
@@ -26,6 +26,12 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2626
misc styles, nothing to do with CSS variables
2727
*/
2828

29+
:root {
30+
--base: #1354ff;
31+
--spacing: 10px;
32+
--blur: 1px;
33+
}
34+
2935
body {
3036
text-align: center;
3137
background: #193549;
@@ -35,6 +41,15 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
3541
font-size: 50px;
3642
}
3743

44+
.hl {
45+
color: var(--base);
46+
}
47+
48+
img {
49+
border: var(--spacing) solid var(--base);
50+
filter: blur(var(--blur));
51+
}
52+
3853
.controls {
3954
margin-bottom: 50px;
4055
}
@@ -45,6 +60,15 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4560
</style>
4661

4762
<script>
63+
var inputs = document.querySelectorAll(`.controls input`);
64+
inputs.forEach(input => input.addEventListener('change', Update));
65+
66+
function Update(e)
67+
{
68+
const suffix = this.dataset.sizing || '';
69+
console.log(e.target.value + suffix);
70+
document.documentElement.style.setProperty(`--${this.name}`, e.target.value + suffix);
71+
}
4872
</script>
4973

5074
</body>

0 commit comments

Comments
 (0)