Skip to content

Commit 51a7c04

Browse files
author
Miguel Bautista
committed
03 done
1 parent e96db65 commit 51a7c04

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

03 - CSS Variables/index-START.html

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,25 @@ <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+
--base: firebrick;
26+
--spacing: 10px;
27+
--blur: 10px;
28+
}
2429

30+
img{
31+
padding: var(--spacing);
32+
background: var(--base);
33+
filter: blur(var(--blur));
34+
}
2535
/*
2636
misc styles, nothing to do with CSS variables
2737
*/
2838

39+
.hl{
40+
color: var(--base);
41+
}
42+
2943
body {
3044
text-align: center;
3145
}
@@ -47,8 +61,7 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4761
}
4862
</style>
4963

50-
<script>
51-
</script>
64+
<script type="text/javascript" src="js/entry.js"></script>
5265

5366
</body>
5467
</html>

03 - CSS Variables/js/entry.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let inputs = document.querySelectorAll('.controls input'); // actually returns a nodelist. Its an array-ish thing. you dont have all the array sugar.
2+
console.log(inputs);
3+
4+
function handleUpdate(){
5+
// let component = this;
6+
let suffix = this.dataset.sizing || '';
7+
// dataset is an obj that contains all the attributes from a particular element. the custom thing in data-
8+
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix)
9+
};
10+
11+
inputs.forEach(input => input.addEventListener('change', handleUpdate));
12+
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));

0 commit comments

Comments
 (0)