-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSS variables.html
63 lines (54 loc) · 1.44 KB
/
CSS variables.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CSS variables</title>
<style>
:root {
--bColor: #ffc600;
--dSize: 10px;
--blur: 0;
}
body {
text-align: center;
background: #193549;
color: white;
font-family: 'helvetica neue', sans-serif;
font-weight: 100;
font-size: 50px;
}
input {
width: 100px;
}
.area {
width: 200px;
height: 200px;
background: var(--bColor);
filter: blur(var(--blur));
padding: var(--dSize);
margin: 100px auto;
}
</style>
</head>
<body>
<div class="controls">
<label for="dSize">Size:</label>
<input id="dSize" type="range" name="dSize" min="10" max="200" value="10" data-sizing="px">
<label for="blur">Blur:</label>
<input id="blur" type="range" name="blur" min="0" max="25" value="0" data-sizing="px">
<label for="bColor">Color:</label>
<input id="bColor" type="color" name="bColor" value="#ffc600">
</div>
<div class="area"></div>
<script>
const inputs = document.querySelectorAll('.controls input');
function handleUpdate() {
const suffix = this.dataset.sizing || '';
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);
}
inputs.forEach(input => input.addEventListener('change', handleUpdate));
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));
console.log(inputs);
</script>
</body>
</html>