Skip to content

Commit 9eb7134

Browse files
committed
Project 28 complete
1 parent 0bce3ea commit 9eb7134

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<title>Video Speed Scrubber</title>
67
<link rel="stylesheet" href="style.css">
78
</head>
9+
810
<body>
911

1012
<div class="wrapper">
11-
<video class="flex" width="765" height="430" src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" loop controls></video>
13+
<video class="flex" width="765" height="430" src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" loop
14+
controls></video>
1215
<div class="speed">
1316
<div class="speed-bar"></div>
1417
</div>
1518
</div>
1619

17-
<script>
18-
</script>
20+
<script src="typescripts.js"></script>
1921
</body>
20-
</html>
22+
23+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var speed = document.querySelector('.speed');
2+
var bar = document.querySelector('.speed-bar');
3+
var video = document.querySelector('.flex');
4+
function handleMove(e) {
5+
var y = e.pageY - this.offsetTop;
6+
var percent = y / this.offsetHeight;
7+
var min = 0.4;
8+
var max = 4;
9+
var height = Math.round(percent * 100) + '%';
10+
var playbackRate = percent * (max - min) + min;
11+
bar.style.height = height;
12+
bar.textContent = playbackRate.toFixed(2) + 'x';
13+
video.playbackRate = playbackRate;
14+
}
15+
speed.addEventListener('mousemove', handleMove);
Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
/**
22
* JavaScript30 by Wes Bos, https://javascript30.com/
33
* TypeScript implementation by Will Wager
4-
* Project:
5-
* Concepts:
6-
* Key takeaways:
7-
* Sidenotes:
4+
* Project: Video Speed Controller
5+
* Concepts: Calculating percent of element above mouse position; Video API
6+
* Key takeaways: Use pageX/Y and offsetTop/Left when scrolling doesn't matter.
7+
* https://stackoverflow.com/questions/6073505/what-is-the-difference-between-screenx-y-clientx-y-and-pagex-y
8+
* https://stackoverflow.com/questions/44172651/difference-between-getboundingclientrect-top-and-offsettop
9+
* Sidenotes: As a general rule, I'll start casting everything selected from the DOM,
10+
* whether the code requires it or not.
811
* Compilation command:
912
* tsc --removeComments --strictNullChecks --noImplicitAny --target es5 typescripts.ts
1013
*/
14+
15+
const speed = document.querySelector('.speed')! as HTMLDivElement;
16+
const bar = document.querySelector('.speed-bar')! as HTMLDivElement;
17+
const video = document.querySelector('.flex')! as HTMLVideoElement;
18+
19+
function handleMove(e: MouseEvent) {
20+
const y = e.pageY - this.offsetTop;
21+
const percent = y / this.offsetHeight;
22+
const min = 0.4;
23+
const max = 4;
24+
const height = Math.round(percent * 100) + '%';
25+
const playbackRate = percent * (max - min) + min;
26+
bar.style.height = height;
27+
bar.textContent = playbackRate.toFixed(2) + 'x';
28+
video.playbackRate = playbackRate;
29+
}
30+
31+
speed.addEventListener('mousemove', handleMove);

0 commit comments

Comments
 (0)