File tree Expand file tree Collapse file tree 3 files changed +47
-26
lines changed Expand file tree Collapse file tree 3 files changed +47
-26
lines changed Original file line number Diff line number Diff line change 3
3
< head >
4
4
< meta charset ="UTF-8 ">
5
5
< title > Scoped CSS Variables and JS</ title >
6
+ < link rel ="stylesheet " href ="style.css ">
6
7
</ head >
7
8
< body >
8
- < h2 > Update CSS Variables with < span class ='hl '> JS</ span > </ h2 >
9
+ < h2 > Update CSS Variables with < span class ='h1 '> JS</ span > </ h2 >
9
10
10
11
< div class ="controls ">
11
12
< label for ="spacing "> Spacing:</ label >
@@ -20,32 +21,8 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
20
21
21
22
< img src ="https://source.unsplash.com/7bwQXzbF6KE/800x500 ">
22
23
23
- < style >
24
24
25
- /*
26
- misc styles, nothing to do with CSS variables
27
- */
28
-
29
- body {
30
- text-align : center;
31
- background : # 193549 ;
32
- color : white;
33
- font-family : 'helvetica neue' , sans-serif;
34
- font-weight : 100 ;
35
- font-size : 50px ;
36
- }
37
-
38
- .controls {
39
- margin-bottom : 50px ;
40
- }
41
-
42
- input {
43
- width : 100px ;
44
- }
45
- </ style >
46
-
47
- < script >
48
- </ script >
25
+ < script type ="text/javascript " src ="script.js "> </ script >
49
26
50
27
</ body >
51
28
</ html >
Original file line number Diff line number Diff line change
1
+ const inputs = 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 ) ) ;
Original file line number Diff line number Diff line change
1
+ : root {
2
+ --base : # ffc600 ;
3
+ --spacing : 10px ;
4
+ --blur : 10px ;
5
+ }
6
+
7
+ img {
8
+ padding : var (--spacing );
9
+ background : var (--base );
10
+ filter : blur (var (--blur ));
11
+ }
12
+
13
+ .h1 {
14
+ color : var (--base );
15
+ }
16
+ /*
17
+ misc styles, nothing to do with CSS variables
18
+ */
19
+
20
+ body {
21
+ text-align : center;
22
+ background : # 193549 ;
23
+ color : white;
24
+ font-family : 'helvetica neue' , sans-serif;
25
+ font-weight : 100 ;
26
+ font-size : 50px ;
27
+ }
28
+
29
+ .controls {
30
+ margin-bottom : 50px ;
31
+ }
32
+
33
+ input {
34
+ width : 100px ;
35
+ }
You can’t perform that action at this time.
0 commit comments