Skip to content

Commit 0a145ca

Browse files
Madison DicksonMadison Dickson
authored andcommitted
More efficient wesbos#3 session
1 parent c8ef5d1 commit 0a145ca

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
@@ -25,6 +25,21 @@ <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+
--spacing: 10px;
30+
--blur: 10px;
31+
--base: #ffc600;
32+
}
33+
34+
.hl {
35+
color: var(--base);
36+
}
37+
38+
img {
39+
padding: var(--spacing);
40+
background: var(--base);
41+
filter: blur(var(--blur));
42+
}
2843

2944
body {
3045
text-align: center;
@@ -45,6 +60,19 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4560
</style>
4661

4762
<script>
63+
document.querySelectorAll('.controls input').forEach(input => {
64+
input.addEventListener("change", updateHandler)
65+
input.addEventListener("mousedown", e => {
66+
//assign single event handler on mousedown
67+
input.onmousemove = updateHandler
68+
})
69+
//remove single event handler on mouseup
70+
input.addEventListener("mouseup", e => (input.onmousemove = null));
71+
})
72+
73+
function updateHandler() {
74+
document.documentElement.style.setProperty(`--${this.name}`, this.value + (this.dataset.sizing || '' ));
75+
}
4876
</script>
4977

5078
</body>

0 commit comments

Comments
 (0)