forked from wesbos/JavaScript30
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
45 lines (36 loc) · 1.17 KB
/
index.html
File metadata and controls
45 lines (36 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Video Speed Scrubber</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="wrapper">
<video class="flex" width="765" height="430" src="https://www.dropbox.com/s/nf6jfkwck1glsyo/12%20-%20flex-wrapping-and-columns.mp4?dl=1" loop controls></video>
<div class="speed">
<div class="speed-bar">1×</div>
</div>
</div>
<script>
const speed = document.querySelector('.speed');
const calcRate = function calcRate(e) {
const y = e.pageY - this.offsetTop;
const percent = y / this.offsetHeight;
const min = 0.4;
const max = 4;
const height = `${Math.round(percent * 100)}%`;
const playbackRate = percent * (max - min) + min;
updateUi(height, playbackRate);
};
const updateUi = function updateUi(height, rate) {
const bar = speed.querySelector('.speed-bar');
const video = document.querySelector('.flex');
bar.style.height = height;
bar.textContent = `${rate.toFixed(2)}x`;
video.playbackRate = rate;
};
speed.addEventListener('mousemove', calcRate);
</script>
</body>
</html>