File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change 11<!DOCTYPE html>
22< html lang ="en ">
3+
34< head >
45 < meta charset ="UTF-8 ">
56 < title > Scoped CSS Variables and JS</ title >
67</ head >
8+
79< body >
810 < h2 > Update CSS Variables with < span class ='hl '> JS</ span > </ h2 >
911
@@ -21,6 +23,17 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
2123 < img src ="https://source.unsplash.com/7bwQXzbF6KE/800x500 ">
2224
2325 < style >
26+ : root {
27+ --base : # ffc600 ;
28+ --spacing : 10px ;
29+ --blur : 10px ;
30+ }
31+
32+ img {
33+ padding : var (--spacing );
34+ background : var (--base );
35+ filter : blur (var (--blur ));
36+ }
2437
2538 /*
2639 misc styles, nothing to do with CSS variables
@@ -45,7 +58,17 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4558 </ style >
4659
4760 < script >
61+ const inputs = document . querySelectorAll ( '.controls input' ) ;
62+
63+ function handleUpdate ( ) {
64+ const suffix = this . dataset . sizing || '' ;
65+ document . documentElement . style . setProperty ( `--${ this . name } ` , this . value + suffix ) ;
66+ }
67+
68+ inputs . forEach ( input => input . addEventListener ( 'change' , handleUpdate ) ) ;
69+ inputs . forEach ( input => input . addEventListener ( 'mousemove' , handleUpdate ) ) ;
4870 </ script >
4971
5072</ body >
51- </ html >
73+
74+ </ html >
You can’t perform that action at this time.
0 commit comments