Skip to content

Commit 894a648

Browse files
committed
wesbos#3 my way
1 parent e0e3616 commit 894a648

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

03 - CSS Variables/index-START.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2222

2323
<style>
2424

25+
:root {
26+
--base: red;
27+
--spacing: 100px;
28+
--blur: 10px;
29+
}
30+
31+
img {
32+
padding: var(--spacing);
33+
filter: blur(var(--blur));
34+
background: var(--base);
35+
}
2536
/*
2637
misc styles, nothing to do with CSS variables
2738
*/
@@ -45,6 +56,23 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4556
</style>
4657

4758
<script>
59+
let inputs = document.querySelectorAll('.controls input');
60+
let handleUpdate = (e) => {
61+
const suffix = this.dataset.sizing || '';
62+
let { id } = e.target;
63+
let image = document.querySelector('img');
64+
if (id === 'spacing'){
65+
image.style.setProperty('--spacing', `${this.value}${suffix}`);
66+
} else if (id === 'blur'){
67+
image.style.setProperty('--blur', `${this.value}${suffix}`);
68+
} else if (id === 'base'){
69+
image.style.setProperty('--base', `${this.value}${suffix}`);
70+
}
71+
72+
}
73+
74+
inputs.forEach(input => input.addEventListener('change', handleUpdate));
75+
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));
4876
</script>
4977

5078
</body>

0 commit comments

Comments
 (0)