File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,17 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2222
2323 < style >
2424
25+ : root {
26+ --base : red;
27+ --spacing : 100px ;
28+ --blur : 10px ;
29+ }
30+
31+ img {
32+ padding : var (--spacing );
33+ filter : blur (var (--blur ));
34+ background : var (--base );
35+ }
2536 /*
2637 misc styles, nothing to do with CSS variables
2738 */
@@ -45,6 +56,23 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4556 </ style >
4657
4758 < script >
59+ let inputs = document . querySelectorAll ( '.controls input' ) ;
60+ let handleUpdate = ( e ) => {
61+ const suffix = this . dataset . sizing || '' ;
62+ let { id } = e . target ;
63+ let image = document . querySelector ( 'img' ) ;
64+ if ( id === 'spacing' ) {
65+ image . style . setProperty ( '--spacing' , `${ this . value } ${ suffix } ` ) ;
66+ } else if ( id === 'blur' ) {
67+ image . style . setProperty ( '--blur' , `${ this . value } ${ suffix } ` ) ;
68+ } else if ( id === 'base' ) {
69+ image . style . setProperty ( '--base' , `${ this . value } ${ suffix } ` ) ;
70+ }
71+
72+ }
73+
74+ inputs . forEach ( input => input . addEventListener ( 'change' , handleUpdate ) ) ;
75+ inputs . forEach ( input => input . addEventListener ( 'mousemove' , handleUpdate ) ) ;
4876 </ script >
4977
5078</ body >
You can’t perform that action at this time.
0 commit comments