Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4207638

Browse files
committed
Finish 03-CSS Variables
1 parent f27a5af commit 4207638

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

03 - CSS Variables/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
3333
font-family: 'helvetica neue', sans-serif;
3434
font-weight: 100;
3535
font-size: 50px;
36+
--spacing: 10px;
37+
--blur: 10px;
38+
--base-color: #ffc600;
39+
3640
}
3741

3842
.controls {
@@ -42,6 +46,18 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4246
input {
4347
width: 100px;
4448
}
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+
}
4561
</style>
4662

4763
<script src="script.js"></script>

03 - CSS Variables/script.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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);

03 - CSS Variables/script.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
);

0 commit comments

Comments
 (0)