Skip to content

Commit 73de491

Browse files
author
Jin Xu
committed
course wesbos#3 finished
1 parent 274b88f commit 73de491

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

03 - CSS Variables/index-START.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
4848
</style>
4949

5050
<script>
51+
const target = document.querySelector('img');
52+
const ctrl_bdr = document.getElementById('spacing');
53+
const ctrl_blur = document.getElementById('blur');
54+
const ctrl_bdrc = document.getElementById('base');
55+
56+
function updateStyle(formctrl, attr){
57+
let unit = formctrl.hasAttribute('data-sizing') ? formctrl.getAttribute('data-sizing') : '';
58+
target.style[attr] = attr === 'filter' ? `blur(${formctrl.value + unit})` : `${formctrl.value + unit}`;
59+
}
60+
61+
window.onload = function(){
62+
target.style.borderStyle = 'solid';
63+
((changes) => {
64+
for(let ctrlAttr in changes) {
65+
updateStyle(changes[ctrlAttr], ctrlAttr);
66+
((attr) => changes[attr].addEventListener('change', function(){
67+
updateStyle(this, attr)
68+
}))(ctrlAttr)
69+
}
70+
})({'borderWidth': ctrl_bdr, 'filter': ctrl_blur, 'borderColor': ctrl_bdrc})
71+
}
5172
</script>
5273

5374
</body>

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
> Folked repo for practice and fun!
66
77
1. [x] ~~JavaScript Drum Kit~~
8-
2. [x] ~~JS + CSS Clock ~~
9-
3. [ ] CSS Variables
10-
4. [ ] Array Cardio, Day 1
8+
2. [x] ~~JS + CSS Clock~~
9+
3. [x] ~~CSS Variables~~
10+
4. [ ] Array Cardio, Day 1
1111
5. [ ] Flex Panel Gallery
1212
6. [ ] Type Ahead
1313
7. [ ] Array Cardio, Day 2

0 commit comments

Comments
 (0)