1xptolevitico69

Rewind Video Effect

Dec 24th, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.78 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title></title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width">
  7. <style>
  8.  
  9. #controls{
  10. display:flex;
  11. justify-content:center;
  12. }
  13.  
  14. #controls button{
  15. margin:0 2px;
  16. }
  17.  
  18. #box{
  19. display:inline-block;
  20. position:absolute;
  21. left:50%;
  22. transform:translate(-50%);
  23. }
  24.  
  25. #range{
  26. width:0;
  27. height:3px;
  28. background-color:red;
  29. display:block;
  30. }
  31.  
  32. #video{
  33. width:900px;
  34. }
  35.  
  36.  
  37. </style>
  38. </head>
  39. <body>
  40.  
  41. <div id='box'>
  42. <video id='video'>
  43. <source src="https://neanderthal-emergen.000webhostapp.com/video1.mp4" type="video/mp4"></video>
  44. <span id='range'></span>
  45.  
  46. <br>
  47.   <div id='controls'>
  48.   <button onclick='play()'>Play</button>
  49.   <button onclick='pause()'>Pause</button>
  50.    <button onclick='forward()'>Forward</button>
  51.   <button onclick='rewind()'>Rewind</button>
  52. </div>
  53. </div>
  54.  
  55.  
  56. <script>
  57.  
  58. video.onloadedmetadata=function(){
  59. w=900;  
  60. f=video.duration;
  61. frange=w/f;          }
  62.  
  63. video.ontimeupdate=function(){
  64. range.style.width=video.currentTime*frange+'px';     }
  65.  
  66.  
  67. video.onended=()=>{
  68. video.currentTime=0;       }
  69.  
  70.  
  71. function play(){
  72.   video.play();
  73.   cancelAnimationFrame(xd);
  74.   cancelAnimationFrame(x);     }
  75.  
  76.  
  77. function pause(){
  78.   video.pause();
  79.   cancelAnimationFrame(xd);
  80.   cancelAnimationFrame(x);         }
  81.  
  82.  
  83. function forward(){
  84.    video.pause();
  85.    a=video.currentTime;  
  86. xd=requestAnimationFrame(forward);
  87.    a=a+0.1;
  88.    video.currentTime=a;
  89.      if(a >= video.duration){
  90.         video.currentTime=0;
  91.         cancelAnimationFrame(xd);
  92.      }
  93.   }
  94.  
  95.  
  96.  
  97. function rewind(){
  98.   video.pause();
  99.   i=video.currentTime;
  100. x=requestAnimationFrame(rewind);
  101.    i=i-0.1;
  102.    video.currentTime=i;
  103.      if(i <= 0){
  104.        cancelAnimationFrame(x);
  105.   }
  106.  }
  107.  
  108.  
  109.  
  110.  
  111. </script>
  112. </body>
  113. </html>
Add Comment
Please, Sign In to add comment