Visitar URL original
Day 3 Complete · wesbos/JavaScript30@9ca01ff · GitHub
Skip to content

Commit 9ca01ff

Browse files
committed
Day 3 Complete
CSS Variables and changing them using javascript
1 parent b933e83 commit 9ca01ff

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2121
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">
2222

2323
<style>
24+
/*
25+
CSS Variables
26+
*/
27+
:root {
28+
--base: #ffc600;
29+
--spacing: 10px;
30+
--blur: 10px;
31+
}
32+
33+
img {
34+
padding: var(--spacing);
35+
background: var(--base);
36+
filter: blur(var(--blur));
37+
}
38+
39+
.hl {
40+
color: var(--base);
41+
}
2442

2543
/*
2644
misc styles, nothing to do with CSS variables
@@ -48,6 +66,19 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4866
</style>
4967

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

5384
</body>

0 commit comments

Comments
 (0)