File tree Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,10 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
33
33
font-family : 'helvetica neue' , sans-serif;
34
34
font-weight : 100 ;
35
35
font-size : 50px ;
36
+ --spacing : 10px ;
37
+ --blur : 10px ;
38
+ --base-color : # ffc600 ;
39
+
36
40
}
37
41
38
42
.controls {
@@ -42,6 +46,18 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
42
46
input {
43
47
width : 100px ;
44
48
}
49
+
50
+ img {
51
+ box-shadow : var (--spacing ) var (--spacing ) 10px 10px var (--base-color );
52
+ filter : blur (var (--blur ));
53
+ will-change : filter;
54
+ z-index : 1 ;
55
+ transform : translate3d (0 , 0 , 0 );
56
+ }
57
+
58
+ .hl {
59
+ color : var (--base-color );
60
+ }
45
61
</ style >
46
62
47
63
< script src ="script.js "> </ script >
Original file line number Diff line number Diff line change
1
+ var $ = function ( selector ) { return document . querySelector ( selector ) ; } ;
2
+ var body = $ ( 'body' ) ;
3
+ var spacingInput = $ ( '#spacing' ) ;
4
+ var blurInput = $ ( '#blur' ) ;
5
+ var baseInput = $ ( '#base' ) ;
6
+ var appendpx = function ( value ) { return value + "px" ; } ;
7
+ var string = function ( value ) { return "" + value ; } ;
8
+ function setListener ( element , propertyName , valueCallback ) {
9
+ element . addEventListener ( 'input' , function ( ) {
10
+ body . style . setProperty ( propertyName , valueCallback ( element . value ) ) ;
11
+ } ) ;
12
+ }
13
+ ;
14
+ setListener ( spacingInput , '--spacing' , appendpx ) ;
15
+ setListener ( blurInput , '--blur' , appendpx ) ;
16
+ setListener ( baseInput , '--base-color' , string ) ;
Original file line number Diff line number Diff line change
1
+ const $ = ( selector ) => document . querySelector ( selector ) ;
2
+
3
+ const body = $ ( 'body' ) ;
4
+ const spacingInput = $ ( '#spacing' ) ;
5
+ const blurInput = $ ( '#blur' ) ;
6
+ const baseInput = $ ( '#base' ) ;
7
+
8
+ const appendpx = ( value ) => `${ value } px` ;
9
+ const string = ( value ) => `${ value } ` ;
10
+
11
+ function setListener (
12
+ element : HTMLInputElement ,
13
+ propertyName : string ,
14
+ valueCallback : ( value : number | string ) => string
15
+ ) {
16
+ element . addEventListener ( 'input' , ( ) => {
17
+ body . style . setProperty ( propertyName , valueCallback ( element . value ) ) ;
18
+ } )
19
+ } ;
20
+
21
+ setListener (
22
+ spacingInput ,
23
+ '--spacing' ,
24
+ appendpx
25
+ ) ;
26
+
27
+ setListener (
28
+ blurInput ,
29
+ '--blur' ,
30
+ appendpx
31
+ ) ;
32
+
33
+ setListener (
34
+ baseInput ,
35
+ '--base-color' ,
36
+ string
37
+ ) ;
You can’t perform that action at this time.
0 commit comments