File tree 3 files changed +25
-7
lines changed
Challenges/03 - Playing with CSS Variables and JS
3 files changed +25
-7
lines changed Original file line number Diff line number Diff line change
1
+ : root {
2
+ --base-color : # f2c94c ;
3
+ --spacing : 10px ;
4
+ --blur : 10px ;
5
+ }
6
+
1
7
@font-face {
2
8
font-family : 'Roboto' ;
3
9
font-style : normal;
@@ -64,8 +70,9 @@ input[type="range"]::-moz-range-track {
64
70
}
65
71
66
72
img {
73
+ background : var (--base-color );
67
74
box-sizing : border-box;
75
+ filter : blur (var (--blur ));
76
+ padding : var (--spacing );
68
77
width : 100% ;
69
- border : 10px solid # 333 ;
70
- filter : blur (.1rem )
71
78
}
Original file line number Diff line number Diff line change
1
+ const inputs = document . querySelectorAll ( 'input' ) ;
2
+
3
+ function handleUpdate ( e ) {
4
+ const suffix = e . target . dataset . metric || '' ;
5
+ document . documentElement . style . setProperty ( `--${ e . target . name } ` , e . target . value + suffix ) ;
6
+ }
7
+
8
+ inputs . forEach ( input => {
9
+ input . addEventListener ( 'change' , handleUpdate ) ;
10
+ input . addEventListener ( 'mousemove' , handleUpdate ) ;
11
+ } ) ;
Original file line number Diff line number Diff line change @@ -18,16 +18,16 @@ <h1 class="title">
18
18
< main >
19
19
< section class ="controls ">
20
20
< label for ="spacing "> Spacing</ label >
21
- < input type ="range " name ="spacing " min ="0 " max ="200 " value =10 >
21
+ < input type ="range " name ="spacing " min ="0 " max ="200 " value =10 data-metric =" px " >
22
22
< label for ="blur "> Blur</ label >
23
- < input type ="range " name ="blur " min ="0 " max ="25 " value =10 >
24
- < label for ="color "> Base Color</ label >
25
- < input type ="color " name ="color " value =#ffc600 >
23
+ < input type ="range " name ="blur " min ="0 " max ="25 " value =10 data-metric =" px " >
24
+ < label for ="base- color "> Base Color</ label >
25
+ < input type ="color " name ="base- color " value =#ffc600 >
26
26
</ section >
27
27
< section >
28
28
< img src ="assets/images/main-image.jpg " title ="Photo by NASA ">
29
29
</ section >
30
30
</ main >
31
- <!-- < script src="./assets/js/script.js"></script> -- >
31
+ < script src ="./assets/js/script.js "> </ script >
32
32
</ body >
33
33
</ html >
You can’t perform that action at this time.
0 commit comments