File tree Expand file tree Collapse file tree 2 files changed +86
-0
lines changed
blur-and-size-adjustment-using-css Expand file tree Collapse file tree 2 files changed +86
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge " />
6+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
7+ < title > CSS Variables</ title >
8+ </ head >
9+ < body >
10+ < h2 > Update CSS variables with < span class ="hl "> JS</ span > </ h2 >
11+ < div class ="controls ">
12+ < label for ="spacing "> Spacing:</ label >
13+ < input
14+ id ="spacing "
15+ type ="range "
16+ name ="spacing "
17+ min ="10 "
18+ max ="200 "
19+ value ="10 "
20+ data-sizing ="px "
21+ />
22+ < label for ="blur "> Blur:</ label >
23+ < input
24+ id ="blur "
25+ type ="range "
26+ name ="blur "
27+ min ="0 "
28+ max ="25 "
29+ value ="10 "
30+ data-sizing ="px "
31+ />
32+ < label for ="base "> Base Color:</ label >
33+ < input type ="color " id ="base " name ="base " value ="#ffc600 " />
34+ </ div >
35+ < img src ="berries.jpg " alt ="Fruits " />
36+ < style >
37+ : root {
38+ --base : # 1cb643 ;
39+ --spacing : 10px ;
40+ --blur : 10px ;
41+
42+ }
43+ img {
44+ filter : blur (var (--blur ));
45+ background : var (--base );
46+ padding : var (--spacing );
47+ height : 100vh ;
48+ width : 45vw ;
49+ }
50+ .hl {
51+ color : var (--base );
52+ }
53+ input {
54+ width : 100px ;
55+ }
56+ body {
57+ text-align : center;
58+ background : # 193549 ;
59+ font-size : 50px ;
60+ font-family : Arial, "Helvetica Neue" , Helvetica, sans-serif;
61+ font-weight : 100 ;
62+ color : white;
63+ background-size : cover;
64+ }
65+ .controls {
66+ margin-bottom : 50px ;
67+ }
68+ </ style >
69+ < script >
70+ const inputs = document . querySelectorAll ( ".controls input" ) ;
71+
72+ function handleUpdate ( ) {
73+ const suffix = this . dataset . sizing || "" ;
74+ document . documentElement . style . setProperty (
75+ `--${ this . name } ` ,
76+ this . value + suffix
77+ ) ;
78+ }
79+
80+ inputs . forEach ( ( input ) => input . addEventListener ( "change" , handleUpdate ) ) ;
81+ inputs . forEach ( ( input ) =>
82+ input . addEventListener ( "mousemove" , handleUpdate )
83+ ) ;
84+ </ script >
85+ </ body >
86+ </ html >
You can’t perform that action at this time.
0 commit comments