File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed
Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -21,10 +21,22 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2121 < img src ="https://source.unsplash.com/7bwQXzbF6KE/800x500 ">
2222
2323 < style >
24+ /* css variable*/
25+ : root {
26+ --base : # ffc600 ;
27+ --spacing : 10px ;
28+ --blur : 10px ;
29+ }
2430
25- /*
26- misc styles, nothing to do with CSS variables
27- */
31+ img {
32+ padding : var (--spacing );
33+ background : var (--base );
34+ filter : blur (var (--blur ));
35+ }
36+
37+ .hl {
38+ color : var (--base );
39+ }
2840
2941 body {
3042 text-align : center;
@@ -48,6 +60,17 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4860 </ style >
4961
5062 < script >
63+ // node list
64+ // this is not an array
65+ var inputs = document . querySelectorAll ( '.controls input' ) ;
66+ function handleUpdate ( ) {
67+ var suffix = this . dataset . sizing || '' ; // object
68+ console . log ( this . dataset ) ;
69+ document . documentElement . style . setProperty ( `--${ this . name } ` , this . value + suffix ) ;
70+ }
71+
72+ inputs . forEach ( input => input . addEventListener ( 'change' , handleUpdate ) ) ;
73+ inputs . forEach ( input => input . addEventListener ( 'mousemove' , handleUpdate ) ) ;
5174 </ script >
5275
5376</ body >
You can’t perform that action at this time.
0 commit comments