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 @@ -25,6 +25,21 @@ <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+ --spacing : 10px ;
30+ --blur : 10px ;
31+ --base : # ffc600 ;
32+ }
33+
34+ .hl {
35+ color : var (--base );
36+ }
37+
38+ img {
39+ padding : var (--spacing );
40+ background : var (--base );
41+ filter : blur (var (--blur ));
42+ }
2843
2944 body {
3045 text-align : center;
@@ -45,6 +60,19 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4560 </ style >
4661
4762 < script >
63+ document . querySelectorAll ( '.controls input' ) . forEach ( input => {
64+ input . addEventListener ( "change" , updateHandler )
65+ input . addEventListener ( "mousedown" , e => {
66+ //assign single event handler on mousedown
67+ input . onmousemove = updateHandler
68+ } )
69+ //remove single event handler on mouseup
70+ input . addEventListener ( "mouseup" , e => ( input . onmousemove = null ) ) ;
71+ } )
72+
73+ function updateHandler ( ) {
74+ document . documentElement . style . setProperty ( `--${ this . name } ` , this . value + ( this . dataset . sizing || '' ) ) ;
75+ }
4876 </ script >
4977
5078</ body >
You can’t perform that action at this time.
0 commit comments