Skip to content

Commit 3a8cded

Browse files
author
Felipe Uliana
committed
[done] wesbos#3 - CSS Variables
1 parent f43d5dd commit 3a8cded

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

03 - CSS Variables/index-START.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2525
/*
2626
misc styles, nothing to do with CSS variables
2727
*/
28+
:root {
29+
--base: #ffc600;
30+
--blur: 10px;
31+
--spacing: 10px;
32+
}
2833

2934
body {
3035
text-align: center;
@@ -50,9 +55,29 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
5055
input {
5156
width:100px;
5257
}
58+
59+
.hl {
60+
color: var(--base);
61+
}
62+
63+
img {
64+
background-color: var(--base);
65+
padding: var(--spacing);
66+
filter: blur(var(--blur));
67+
}
5368
</style>
5469

5570
<script>
71+
const inputs = document.querySelectorAll('.controls input')
72+
73+
inputs.forEach(input => input.addEventListener('change', handleUpdate));
74+
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));
75+
76+
function handleUpdate() {
77+
const suffix = this.dataset.sizing || '';
78+
79+
document.documentElement.style.setProperty(`--${this.name}`, (this.value + suffix));
80+
}
5681
</script>
5782

5883
</body>

0 commit comments

Comments
 (0)