File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed
28 - Video Speed Controller Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 1010 < div class ="wrapper ">
1111 < video class ="flex " width ="765 " height ="430 " src ="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4 " loop controls > </ video >
1212 < div class ="speed ">
13- < div class ="speed-bar "> 1× </ div >
13+ < div class ="speed-bar "> 1.0x </ div >
1414 </ div >
1515 </ div >
1616
1717< script >
18+ const speed = document . querySelector ( '.speed' ) ;
19+ const bar = speed . querySelector ( '.speed-bar' ) ;
20+ const video = document . querySelector ( '.flex' ) ;
21+
22+ // get all properties of video DOM element:
23+ // https://davidwalsh.name/javascript-attributes
24+
25+ function showElemAtts ( elem ) {
26+ let atts = Array . from ( elem . attributes ) ;
27+ console . log ( atts ) ;
28+ }
29+ // showElemAtts(video);
30+
31+ function handleMove ( e ) {
32+ const y = e . pageY - this . offsetTop ;
33+ const decimal = y / this . offsetHeight ;
34+ const percent = Math . round ( decimal * 100 ) + '%' ;
35+
36+ // playback rate vars
37+ const min = 0.4 ;
38+ const max = 4 ;
39+ const playbackRate = decimal * ( max - min ) + min ;
40+
41+ // apply styles to bar
42+ bar . style . height = percent ;
43+ bar . textContent = playbackRate . toFixed ( 1 ) + 'x' ;
44+
45+ // apply rate to video
46+ video . playbackRate = playbackRate ;
47+ }
48+
49+ speed . addEventListener ( 'mousemove' , handleMove ) ;
1850</ script >
51+
1952</ body >
2053</ html >
Original file line number Diff line number Diff line change 99 font-family : sans-serif;
1010}
1111.wrapper {
12- width : 850px ;
12+ /* width:850px; */
1313 display : flex;
1414}
1515video {
@@ -36,4 +36,6 @@ video {
3636 padding : 2px ;
3737 color : white;
3838 height : 16.3% ;
39+ cursor : -webkit-grabbing;
40+ cursor : grabbing;
3941}
You can’t perform that action at this time.
0 commit comments