Visitar URL original
JS30 #3 · ines-akrap/JavaScript30@e19b74d · GitHub
Skip to content
This repository was archived by the owner on Apr 11, 2020. It is now read-only.

Commit e19b74d

Browse files
committed
JS30 wesbos#3
1 parent 77f6a7b commit e19b74d

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Scoped CSS Variables and JS</title>
6+
</head>
7+
<body>
8+
<h2>Update CSS Variables with <span class='hl'>JS</span></h2>
9+
10+
<div class="controls">
11+
<label for="spacing">Spacing:</label>
12+
<input id="spacing" type="range" name="spacing" min="10" max="200" value="10" data-sizing="px">
13+
14+
<label for="blur">Blur:</label>
15+
<input id="blur" type="range" name="blur" min="0" max="25" value="10" data-sizing="px">
16+
17+
<label for="base">Base Color</label>
18+
<input id="base" type="color" name="base" value="#ffc600">
19+
</div>
20+
21+
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">
22+
23+
<style>
24+
:root {
25+
--base: yellow;
26+
--spacing: 20px;
27+
--blur: 10px;
28+
}
29+
30+
img {
31+
padding: var(--spacing);
32+
background: var(--base);
33+
filter: blur(var(--blur));
34+
}
35+
36+
hl {
37+
color: var(--base);
38+
}
39+
40+
body {
41+
text-align: center;
42+
background: #193549;
43+
color: white;
44+
font-family: 'helvetica neue', sans-serif;
45+
font-weight: 100;
46+
font-size: 50px;
47+
}
48+
49+
.controls {
50+
margin-bottom: 50px;
51+
}
52+
53+
input {
54+
width: 100px;
55+
}
56+
</style>
57+
58+
<script>
59+
const inputs = document.querySelectorAll('.controls input');
60+
61+
function handleUpdate() {
62+
const suffix = this.dataset.sizing || '';
63+
document.documentElement.style.setProperty(`--${this.name}`, `${this.value}${suffix}`);
64+
}
65+
66+
inputs.forEach((input) => {
67+
input.addEventListener('change', handleUpdate);
68+
input.addEventListener('mousemove', handleUpdate);
69+
});
70+
</script>
71+
72+
</body>
73+
</html>

0 commit comments

Comments
 (0)