File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,11 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2525 /*
2626 misc styles, nothing to do with CSS variables
2727 */
28+ : root {
29+ --base : # ffc600 ;
30+ --blur : 10px ;
31+ --spacing : 10px ;
32+ }
2833
2934 body {
3035 text-align : center;
@@ -50,9 +55,29 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
5055 input {
5156 width : 100px ;
5257 }
58+
59+ .hl {
60+ color : var (--base );
61+ }
62+
63+ img {
64+ background-color : var (--base );
65+ padding : var (--spacing );
66+ filter : blur (var (--blur ));
67+ }
5368 </ style >
5469
5570 < script >
71+ const inputs = document . querySelectorAll ( '.controls input' )
72+
73+ inputs . forEach ( input => input . addEventListener ( 'change' , handleUpdate ) ) ;
74+ inputs . forEach ( input => input . addEventListener ( 'mousemove' , handleUpdate ) ) ;
75+
76+ function handleUpdate ( ) {
77+ const suffix = this . dataset . sizing || '' ;
78+
79+ document . documentElement . style . setProperty ( `--${ this . name } ` , ( this . value + suffix ) ) ;
80+ }
5681 </ script >
5782
5883</ body >
You can’t perform that action at this time.
0 commit comments