forked from wesbos/JavaScript30
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex-jds.html
More file actions
65 lines (54 loc) · 1.59 KB
/
index-jds.html
File metadata and controls
65 lines (54 loc) · 1.59 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Scoped CSS Variables and JS</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Update CSS Variables with <span class='hl'>JS</span></h2>
<div class="controls">
<label for="spacing">Spacing:
<input type="range" name="spacing" min="10" max="200" value="10" data-sizing="px">
</label>
<label for="blur">Blur:
<input type="range" name="blur" min="0" max="25" value="10" data-sizing="px">
</label>
<label for="base">Base Color
<input type="color" name="base" value="#ffc600">
</label>
</div>
<img src="photo.jpg">
<style>
:root {
--base:#ffc600;
--spacing:10px;
--blur:10px;
}
img {
padding: var(--spacing);
background: var(--base);
filter:blur(var(--blur));
}
.hl {
color: var(--base);
}
</style>
<script>
const inputs = document.querySelectorAll('.controls input');
// console.log('inputs: ', inputs);
function handleUpdate() {
// console.log('this: ', this);
console.log('this.value: ',this.value);
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));
/*
listening for mouse move over the input is a bit imprecise...
could set a flog on mouse click to enable listening for mousemove
*/
</script>
</body>
</html>