Visitar URL original
solution #3 · rustamyusupov/JavaScript30@d9c0ac2 · GitHub
Skip to content
This repository was archived by the owner on Feb 13, 2022. It is now read-only.

Commit d9c0ac2

Browse files
committed
solution wesbos#3
1 parent fb5b0eb commit d9c0ac2

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

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

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

2323
<style>
2424

25-
/*
26-
misc styles, nothing to do with CSS variables
27-
*/
25+
:root {
26+
--base: #ffc600;
27+
--spacing: 10px;
28+
--blur: 10px;
29+
}
30+
31+
.hl {
32+
color: var(--base);
33+
}
34+
35+
img {
36+
background: var(--base);
37+
padding: var(--spacing);
38+
filter: blur(var(--blur));
39+
}
2840

2941
body {
3042
text-align: center;
@@ -53,6 +65,16 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
5365
</style>
5466

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

5880
</body>

0 commit comments

Comments
 (0)