File tree Expand file tree Collapse file tree 3 files changed +47
-8
lines changed
28 - Video Speed Controller Expand file tree Collapse file tree 3 files changed +47
-8
lines changed Original file line number Diff line number Diff line change 1
1
<!DOCTYPE html>
2
2
< html lang ="en ">
3
+
3
4
< head >
4
5
< meta charset ="UTF-8 ">
5
6
< title > Video Speed Scrubber</ title >
6
7
< link rel ="stylesheet " href ="style.css ">
7
8
</ head >
9
+
8
10
< body >
9
11
10
12
< 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 >
12
15
< div class ="speed ">
13
16
< div class ="speed-bar "> 1×</ div >
14
17
</ div >
15
18
</ div >
16
19
17
- < script >
18
- </ script >
20
+ < script src ="typescripts.js "> </ script >
19
21
</ body >
20
- </ html >
22
+
23
+ </ html >
Original file line number Diff line number Diff line change
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 ) ;
Original file line number Diff line number Diff line change 1
1
/**
2
2
* JavaScript30 by Wes Bos, https://javascript30.com/
3
3
* 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.
8
11
* Compilation command:
9
12
* tsc --removeComments --strictNullChecks --noImplicitAny --target es5 typescripts.ts
10
13
*/
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 ) ;
You can’t perform that action at this time.
0 commit comments