Skip to content

Commit 8e6ab5f

Browse files
committed
Finished
1 parent e762cdd commit 8e6ab5f

File tree

3 files changed

+33
-81
lines changed

3 files changed

+33
-81
lines changed

03 - CSS Variables/cssVariables.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// this is selecting all the input elements and controls atributes in the HTML document
2+
const inputs = document.querySelectorAll('.controls input');
3+
4+
function handleUpdate() {
5+
//
6+
const suffix = this.dataset.sizing || '';
7+
8+
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);
9+
console.log(suffix);
10+
}
11+
12+
// this updates the inputs
13+
inputs.forEach(input => input.addEventListener('change', handleUpdate));
14+
// this updates the inputs as the mouse moves
15+
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));

03 - CSS Variables/index-FINISHED.html

Lines changed: 0 additions & 79 deletions
This file was deleted.

03 - CSS Variables/index-START.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2222

2323
<style>
2424

25+
/* This is for creating a CSS variable*/
26+
:root {
27+
--base: #ffc600;
28+
--spacing: 10px;
29+
--blur: 10px;
30+
}
31+
32+
img {
33+
padding: var(--spacing);
34+
background: var(--base);
35+
filter: blur(var(--blur));
36+
}
37+
38+
.hl {
39+
color: var(--base);
40+
}
41+
2542
/*
2643
misc styles, nothing to do with CSS variables
2744
*/
@@ -47,8 +64,7 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4764
}
4865
</style>
4966

50-
<script>
51-
</script>
67+
<script src="cssVariables.js"></script>
5268

5369
</body>
5470
</html>

0 commit comments

Comments
 (0)