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

Skip to content

Commit 605be60

Browse files
author
Jin Xu
committed
course wesbos#10 finished
1 parent 19e85f7 commit 605be60

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

10 - Hold Shift and Check Checkboxes/index-START.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,35 @@
104104
</div>
105105

106106
<script>
107+
let shiftPressing = 0;
108+
let prevIdx = [0, 0];
109+
110+
window.addEventListener('keydown', e => {
111+
if(e.keyCode === 16) {
112+
shiftPressing = 1;
113+
}
114+
});
115+
window.addEventListener('keyup', e => {
116+
if(e.keyCode === 16) {
117+
shiftPressing = 0;
118+
}
119+
});
120+
121+
[...document.querySelectorAll('input[type="checkbox"]')].forEach((ele, index) => {
122+
ele.addEventListener('change', function (e) {
123+
if(this.checked){
124+
prevIdx.shift();
125+
prevIdx.push(index);
126+
}
127+
if(this.checked && shiftPressing) {
128+
[...document.querySelectorAll('input[type="checkbox"]')].forEach((el,idx) => {
129+
if((idx <= prevIdx[1] && idx >= prevIdx[0]) || (idx >= prevIdx[1] && idx <= prevIdx[0])){
130+
el.checked = true;
131+
}
132+
})
133+
}
134+
})
135+
})
107136
</script>
108137
</body>
109138
</html>

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
7. [x] ~~Array Cardio, Day 2~~
1414
8. [x] ~~Fun with HTML5 Canvas~~
1515
9. [x] ~~Dev Tools Domination~~
16-
10. [ ] Hold Shift and Check Checkboxes
16+
10. [x] ~~Hold Shift and Check Checkboxes~~
1717
11. [ ] Custom Video Player
1818
12. [ ] Key Sequence Detection
1919
13. [ ] Slide in on Scroll

0 commit comments

Comments
 (0)