11<!DOCTYPE html>
22< html lang ="en ">
3+
34< head >
45 < meta charset ="UTF-8 ">
56 < title > Scoped CSS Variables and JS</ title >
6- </ head >
7- < body >
8- < h2 > Update CSS Variables with < span class ='hl '> JS</ span > </ h2 >
9-
10- < div class ="controls ">
11- < label for ="spacing "> Spacing:</ label >
12- < input type ="range " name ="spacing " min ="10 " max ="200 " value ="10 " data-sizing ="px ">
13-
14- < label for ="blur "> Blur:</ label >
15- < input type ="range " name ="blur " min ="0 " max ="25 " value ="10 " data-sizing ="px ">
16-
17- < label for ="base "> Base Color</ label >
18- < input type ="color " name ="base " value ="#ffc600 ">
19- </ div >
20-
21- < img src ="https://source.unsplash.com/7bwQXzbF6KE/800x500 ">
227
238 < style >
249 : root {
25- --base : # ffc600 ;
26- --spacing : 10px ;
10+ --base : goldenrod;
2711 --blur : 10px ;
12+ --spacing : 10px ;
2813 }
2914
3015 img {
31- padding : var (--spacing );
3216 background : var (--base );
3317 filter : blur (var (--blur ));
18+ padding : var (--spacing );
3419 }
3520
3621 .hl {
3722 color : var (--base );
3823 }
3924
40- /*
41- misc styles, nothing to do with CSS variables
42- */
43-
4425 body {
4526 text-align : center;
4627 }
@@ -66,19 +47,36 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
6647 width : 100px ;
6748 }
6849 </ style >
50+ </ head >
6951
70- < script >
71- const inputs = document . querySelectorAll ( '.controls input' ) ;
52+ < body >
53+ < h2 > Update CSS Variables with < span class =' hl ' > JS </ span > </ h2 >
7254
73- function handleUpdate ( ) {
74- const suffix = this . dataset . sizing || '' ;
75- document . documentElement . style . setProperty ( `--${ this . name } ` , this . value + suffix ) ;
76- }
55+ < div class ="controls ">
56+ < label for ="spacing "> Spacing:</ label >
57+ < input type ="range " name ="spacing " min ="10 " max ="200 " value ="10 " data-sizing ="px ">
7758
78- inputs . forEach ( input => input . addEventListener ( 'change' , handleUpdate ) ) ;
79- inputs . forEach ( input => input . addEventListener ( 'mousemove' , handleUpdate ) ) ;
80- </ script >
59+ < label for ="blur "> Blur:</ label >
60+ < input type ="range " name ="blur " min ="0 " max ="25 " value ="10 " data-sizing ="px ">
8161
62+ < label for ="base "> Base Color</ label >
63+ < input type ="color " name ="base " value ="#ffc600 ">
64+ </ div >
65+
66+ < img src ="https://source.unsplash.com/7bwQXzbF6KE/800x500 ">
67+
68+ < script >
69+ const inputs = document . querySelectorAll ( '.controls input' ) ;
70+
71+ function handleUpdate ( ) {
72+ const suffix = this . dataset . sizing || '' ;
73+ document . documentElement . style . setProperty ( `--${ this . name } ` , this . value + suffix )
74+ }
75+
76+ inputs . forEach ( input => input . addEventListener ( 'change' , handleUpdate ) ) ;
77+ inputs . forEach ( input => input . addEventListener ( 'mousemove' , handleUpdate ) ) ;
78+ </ script >
8279
8380</ body >
84- </ html >
81+
82+ </ html >
0 commit comments