File tree Expand file tree Collapse file tree 3 files changed +82
-0
lines changed
72. Update CSS Variables Using JavaScript Expand file tree Collapse file tree 3 files changed +82
-0
lines changed Original file line number Diff line number Diff line change 1+ const input = document . querySelectorAll ( ".controls input" ) ;
2+
3+ function handleUpdate ( ) {
4+ // console.log(this.name);
5+ this . name == "base" ? ( suppix = "" ) : ( suppix = "px" ) ;
6+ document . documentElement . style . setProperty (
7+ `--${ this . name } ` ,
8+ this . value + suppix
9+ ) ;
10+ }
11+
12+ input . forEach ( ( input ) => input . addEventListener ( "change" , handleUpdate ) ) ;
Original file line number Diff line number Diff line change 1+ < html lang ="en ">
2+ < head >
3+ < meta charset ="UTF-8 " />
4+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < title > Update CSS</ title >
7+ < link rel ="stylesheet " href ="style.css " />
8+ </ head >
9+ < body >
10+ < div class ="container ">
11+ < div class ="controls ">
12+ < label for ="spacing "> Spacing:</ label >
13+ < input
14+ type ="range "
15+ id ="spacing "
16+ name ="spacing "
17+ min ="10 "
18+ max ="200 "
19+ value ="10 "
20+ />
21+
22+ < label for ="blur "> Blur:</ label >
23+ < input type ="range " id ="blur " name ="blur " min ="0 " max ="25 " value ="10 " />
24+
25+ < label for ="base "> Color:</ label >
26+ < input type ="color " id ="base " name ="base " value ="#ffc600 " />
27+ </ div >
28+
29+ < img
30+ src ="https://images.unsplash.com/photo-1469474968028-56623f02e42e?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1174&q=80 "
31+ />
32+ </ div >
33+
34+ < script src ="app.js "> </ script >
35+ </ body >
36+ </ html >
Original file line number Diff line number Diff line change 1+ * {
2+ padding : 0 ;
3+ margin : 0 ;
4+ }
5+
6+ : root {
7+ --base : # ffc600 ;
8+ --spacing : 10px ;
9+ --blur : 2px ;
10+ }
11+
12+ .container {
13+ text-align : center;
14+ font-family : sans-serif;
15+ font-size : 20px ;
16+ margin : 20px ;
17+ }
18+
19+ .controls {
20+ margin-bottom : 50px ;
21+ }
22+
23+ img {
24+ padding : var (--spacing );
25+ background : var (--base );
26+ filter : blur (var (--blur ));
27+ width : 100vh ;
28+ }
29+
30+ input {
31+ width : 100px ;
32+ border : none;
33+ background : transparent;
34+ }
You can’t perform that action at this time.
0 commit comments