forked from wesbos/JavaScript30
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
73 lines (63 loc) · 1.71 KB
/
index.html
File metadata and controls
73 lines (63 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
<style>
body {
background-color: #193549;
color: white;
text-align: center;
font-family: "helvetica neue", sans-serif;
font-size: 2.5rem;
font-weight: 100;
}
img {
padding: var(--padding);
background-color: var(--color);
filter: blur(var(--blur));
}
.highlight {
color: var(--color);
}
.controls,
.controls > label {
display: flex;
align-items: center;
justify-content: center;
gap: 16px;
}
.controls {
gap: 48px;
margin-bottom: 48px;
}
</style>
</head>
<body>
<h1>Update CSS Variables with <span class="highlight">JS</span></h1>
<div class="controls">
<label
>Padding: <input name="padding" type="range" data-units="px" value="10"
/></label>
<label
>Blur: <input name="blur" type="range" data-units="px" value="10"
/></label>
<label>Color: <input name="color" type="color" value="#f5be44" /></label>
</div>
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500" alt="" />
<script>
const sync = (input) => {
const units = input.dataset.units || "";
document.documentElement.style.setProperty(
`--${input.name}`,
input.value + units
);
};
document.querySelectorAll(".controls input").forEach((input) => {
input.addEventListener("change", (e) => sync(e.currentTarget));
input.addEventListener("mousemove", (e) => sync(e.currentTarget));
sync(input);
});
</script>
</body>
</html>