Visitar URL original
learned and finished day11-13 · soyaine/JavaScript30@10e8ea6 · GitHub
Skip to content

Commit 10e8ea6

Browse files
committed
learned and finished day11-13
1 parent 761545f commit 10e8ea6

4 files changed

Lines changed: 87 additions & 1 deletion

File tree

‎11 - Custom Video Player/index.html‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
</div>
2323
</div>
2424

25-
<script src="scripts-FINISHED.js"></script>
25+
<!-- <script src="scripts-FINISHED.js"></script> -->
26+
<script src="scripts.js"></script>
2627
</body>
2728
</html>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const player = document.querySelector('.player');
2+
const video = player.querySelector('.viewer');
3+
const progress = player.querySelector('.progress');
4+
const progressBar = player.querySelector('.progress__filled');
5+
const toggle = player.querySelector('.toggle');
6+
const skipButtons = player.querySelectorAll('[data-skip]');
7+
const ranges = player.querySelectorAll('.player__slider');
8+
9+
function tooglePlay() {
10+
const method = video.paused ? 'play' : 'pause';
11+
video[method]();
12+
}
13+
14+
function updateButton() {
15+
const icon = this.paused ? '►' : '❚ ❚';
16+
toggle.textContent = icon;
17+
}
18+
19+
function skip() {
20+
video.currentTime += parseFloat(this.dataset.skip);
21+
}
22+
23+
function rangeUpdate() {
24+
video[this.name] = this.value;
25+
}
26+
27+
function handleProgress() {
28+
const percent = (video.currentTime / video.duration) * 100;
29+
progressBar.style.flexBasis = `${percent}%`;
30+
}
31+
32+
function scrub(e) {
33+
const scrubTime = (e.offsetX / progress.offsetWidth) * video.duration;
34+
video.currentTime = scrubTime;
35+
}
36+
37+
38+
video.addEventListener('click', tooglePlay);
39+
video.addEventListener('play', updateButton);
40+
video.addEventListener('pause', updateButton);
41+
video.addEventListener('timeupdate', handleProgress);
42+
43+
toggle.addEventListener('click', tooglePlay);
44+
skipButtons.forEach(btn => btn.addEventListener('click',skip));
45+
ranges.forEach(range => range.addEventListener('change',rangeUpdate));
46+
ranges.forEach(range => range.addEventListener('mousemove',rangeUpdate));
47+
48+
let mousedown = false;
49+
progress.addEventListener('click',scrub);
50+
progress.addEventListener('mousemove',(e)=> mousedown && scrub(e));
51+
progress.addEventListener('mousedown', ()=> mousedown = true);
52+
progress.addEventListener('mouseup',()=> mousedown = false);

‎12 - Key Sequence Detection/index-START.html‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>Key Detection</title>
6+
<p>try to press the secretCode</p>
67
<script type="text/javascript" src="http://www.cornify.com/js/cornify.js"></script>
78
</head>
89
<body>
910
<script>
11+
const pressed = [];
12+
const secretCode = 'helloworld';
13+
window.addEventListener('keyup', (e)=>{
14+
console.log(e.key);
15+
pressed.push(e.key);
16+
//splice(start-index(included),deletecount);
17+
pressed.splice(-secretCode.length-1, pressed.length - secretCode.length);
18+
if(pressed.join('').includes(secretCode)) {
19+
cornify_add();
20+
}
21+
console.log(pressed);
22+
})
1023
</script>
1124
</body>
1225
</html>

‎13 - Slide in on Scroll/index-START.html‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@ <h1>Slide in on Scroll</h1>
5858
};
5959
}
6060

61+
const slideImages = document.querySelectorAll('.slide-in');
62+
function checkSlide(e) {
63+
slideImages.forEach(img => {
64+
const slideInAt = (window.scrollY + window.innerHeight) - img.height /2;
65+
const imgBottom = img.offsetTop + img.height;
66+
67+
// scroll halfway through the image
68+
const isHalfShow = slideInAt > img.offsetTop;
69+
// the image not scroll out of the window yet
70+
const isNotScrollPast = window.scrollY < imgBottom;
71+
72+
if(isHalfShow && isNotScrollPast) {
73+
img.classList.add('active');
74+
}else{
75+
img.classList.remove('active');
76+
}
77+
})
78+
}
79+
80+
window.addEventListener('scroll',debounce(checkSlide));
6181
</script>
6282

6383
<style>

0 commit comments

Comments
 (0)