File tree 3 files changed +36
-3
lines changed
3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change 1
1
<!DOCTYPE html>
2
2
< html lang ="en ">
3
+
3
4
< head >
4
5
< meta charset ="UTF-8 ">
5
6
< title > Scoped CSS Variables and JS</ title >
6
7
</ head >
8
+
7
9
< body >
8
10
< h2 > Update CSS Variables with < span class ='hl '> JS</ span > </ h2 >
9
11
@@ -21,6 +23,21 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
21
23
< img src ="https://source.unsplash.com/7bwQXzbF6KE/800x500 ">
22
24
23
25
< style >
26
+ : root {
27
+ --base : # ffc600 ;
28
+ --spacing : 10px ;
29
+ --blur : 10px ;
30
+ }
31
+
32
+ img {
33
+ padding : var (--spacing );
34
+ background : var (--base );
35
+ filter : blur (var (--blur ));
36
+ }
37
+
38
+ .hl {
39
+ color : var (--base );
40
+ }
24
41
25
42
/*
26
43
misc styles, nothing to do with CSS variables
@@ -44,8 +61,8 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
44
61
}
45
62
</ style >
46
63
47
- < script >
48
- </ script >
64
+ < script src ="typescripts.js "> </ script >
49
65
50
66
</ body >
51
- </ html >
67
+
68
+ </ html >
Original file line number Diff line number Diff line change
1
+ var inputs = document . querySelectorAll ( '.controls input' ) ;
2
+ function handleUpdate ( ) {
3
+ var suffix = this . dataset . sizing || '' ;
4
+ document . documentElement . style . setProperty ( "--" + this . name , this . value + suffix ) ;
5
+ }
6
+ inputs . forEach ( function ( input ) { return input . addEventListener ( 'change' , handleUpdate ) ; } ) ;
7
+ inputs . forEach ( function ( input ) { return input . addEventListener ( 'mousemove' , handleUpdate ) ; } ) ;
Original file line number Diff line number Diff line change
1
+ const inputs : NodeList = document . querySelectorAll ( '.controls input' ) ;
2
+
3
+ function handleUpdate ( ) {
4
+ const suffix = this . dataset . sizing || '' ;
5
+ document . documentElement . style . setProperty ( `--${ this . name } ` , this . value + suffix ) ;
6
+ }
7
+
8
+ inputs . forEach ( input => input . addEventListener ( 'change' , handleUpdate ) ) ;
9
+ inputs . forEach ( input => input . addEventListener ( 'mousemove' , handleUpdate ) ) ;
You can’t perform that action at this time.
0 commit comments