File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -21,11 +21,25 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2121 < img src ="https://source.unsplash.com/7bwQXzbF6KE/800x500 ">
2222
2323 < style >
24+ : root {
25+ --base : firebrick;
26+ --spacing : 10px ;
27+ --blur : 10px ;
28+ }
2429
30+ img {
31+ padding : var (--spacing );
32+ background : var (--base );
33+ filter : blur (var (--blur ));
34+ }
2535 /*
2636 misc styles, nothing to do with CSS variables
2737 */
2838
39+ .hl {
40+ color : var (--base );
41+ }
42+
2943 body {
3044 text-align : center;
3145 }
@@ -47,8 +61,7 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4761 }
4862 </ style >
4963
50- < script >
51- </ script >
64+ < script type ="text/javascript " src ="js/entry.js "> </ script >
5265
5366</ body >
5467</ html >
Original file line number Diff line number Diff line change 1+ let inputs = document . querySelectorAll ( '.controls input' ) ; // actually returns a nodelist. Its an array-ish thing. you dont have all the array sugar.
2+ console . log ( inputs ) ;
3+
4+ function handleUpdate ( ) {
5+ // let component = this;
6+ let suffix = this . dataset . sizing || '' ;
7+ // dataset is an obj that contains all the attributes from a particular element. the custom thing in data-
8+ document . documentElement . style . setProperty ( `--${ this . name } ` , this . value + suffix )
9+ } ;
10+
11+ inputs . forEach ( input => input . addEventListener ( 'change' , handleUpdate ) ) ;
12+ inputs . forEach ( input => input . addEventListener ( 'mousemove' , handleUpdate ) ) ;
You can’t perform that action at this time.
0 commit comments