Visitar URL original
changes · wesbos/JavaScript30@c9a1db2 · GitHub
Skip to content

Commit c9a1db2

Browse files
committed
changes
1 parent 6c801c3 commit c9a1db2

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎03 - CSS Variables/index-START.html‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,23 @@ <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+
--spacing:10px;
26+
--blur: 2px;
27+
--base: #fff221;
2428

29+
}
30+
31+
img{
32+
background: var(--base);
33+
padding: var(--spacing);
34+
filter: blur(var(--blur));
35+
}
36+
37+
38+
.hl{
39+
color: var(--base);
40+
}
2541
/*
2642
misc styles, nothing to do with CSS variables
2743
*/
@@ -48,6 +64,16 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4864
</style>
4965

5066
<script>
67+
const inputs = document.querySelectorAll('.controls input');
68+
function handleUpdate(){
69+
const suffix = this.dataset.sizing || '';
70+
document.documentElement.style.setProperty(`--${this.name}`,this.value +suffix);
71+
72+
}
73+
74+
inputs.forEach(input => input.addEventListener('change', handleUpdate));
75+
76+
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));
5177
</script>
5278

5379
</body>

0 commit comments

Comments
 (0)