File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,9 +22,17 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2222
2323 < style >
2424
25- /*
26- misc styles, nothing to do with CSS variables
27- */
25+ : root {
26+ --base : # ffc600 ;
27+ --spacing : 10px ;
28+ --blur : 10px ;
29+ }
30+
31+ img {
32+ padding : var (--spacing );
33+ background : var (--base );
34+ filter : blur (var (--blur ));
35+ }
2836
2937 body {
3038 text-align : center;
@@ -53,6 +61,14 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
5361 </ style >
5462
5563 < script >
64+ const controls = document . querySelectorAll ( '.controls input' ) ;
65+
66+ const handleUpdate = ( e ) => {
67+ const suffix = e . target . dataset . sizing || '' ;
68+ document . documentElement . style . setProperty ( `--${ e . target . name } ` , e . target . value + suffix ) ;
69+ }
70+ controls . forEach ( control => control . addEventListener ( 'change' , handleUpdate ) ) ;
71+ // controls.forEach(control => control.addEventListener('mousemove', handleUpdate));
5672 </ script >
5773
5874</ body >
You can’t perform that action at this time.
0 commit comments