File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,20 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
21
21
< img src ="https://source.unsplash.com/7bwQXzbF6KE/800x500 ">
22
22
23
23
< style >
24
+ : root {
25
+ --base : red;
26
+ --spacing : 10px ;
27
+ --blur : 10px ;
28
+ }
24
29
30
+ img {
31
+ padding : var (--spacing );
32
+ background : var (--base );
33
+ filter : blur (var (--blur ));
34
+ }
35
+
36
+ .hl {
37
+ color : var (--base ); }
25
38
/*
26
39
misc styles, nothing to do with CSS variables
27
40
*/
@@ -48,6 +61,16 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
48
61
</ style >
49
62
50
63
< script >
64
+ const inputs = document . querySelectorAll ( '.controls input' ) ;
65
+
66
+ function handleUpdate ( ) {
67
+ const suffix = this . dataset . sizing || '' ;
68
+ document . documentElement . style . setProperty ( `--${ this . name } ` , this . value + suffix )
69
+ }
70
+
71
+ inputs . forEach ( input => input . addEventListener ( 'change' , handleUpdate ) ) ;
72
+ inputs . forEach ( input => input . addEventListener ( 'mousemove' , handleUpdate ) ) ;
73
+
51
74
</ script >
52
75
53
76
</ body >
You can’t perform that action at this time.
0 commit comments