Skip to content

Commit e2c70e2

Browse files
committed
Finished project 3
1 parent 885abbc commit e2c70e2

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

03 - CSS Variables/index-START.html

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<title>Scoped CSS Variables and JS</title>
67
</head>
8+
79
<body>
810
<h2>Update CSS Variables with <span class='hl'>JS</span></h2>
911

@@ -21,6 +23,21 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2123
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">
2224

2325
<style>
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+
}
2441

2542
/*
2643
misc styles, nothing to do with CSS variables
@@ -44,8 +61,8 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4461
}
4562
</style>
4663

47-
<script>
48-
</script>
64+
<script src="typescripts.js"></script>
4965

5066
</body>
51-
</html>
67+
68+
</html>

03 - CSS Variables/typescripts.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var inputs = document.querySelectorAll('.controls input');
2+
function handleUpdate() {
3+
var suffix = this.dataset.sizing || '';
4+
document.documentElement.style.setProperty("--" + this.name, this.value + suffix);
5+
}
6+
inputs.forEach(function (input) { return input.addEventListener('change', handleUpdate); });
7+
inputs.forEach(function (input) { return input.addEventListener('mousemove', handleUpdate); });

03 - CSS Variables/typescripts.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const inputs: NodeList = document.querySelectorAll('.controls input');
2+
3+
function handleUpdate() {
4+
const suffix = this.dataset.sizing || '';
5+
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);
6+
}
7+
8+
inputs.forEach(input => input.addEventListener('change', handleUpdate));
9+
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));

0 commit comments

Comments
 (0)