Guest User

Untitled

a guest
Dec 15th, 2020
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. $(function(){
  3.     $(window).scroll(function(){
  4.  
  5.         var video = document.getElementById("video");
  6.         var elemPos = video.getBoundingClientRect().bottom;
  7.         var elemHeight = $('#video').height();
  8.  
  9.         var pos = elemHeight / 2;
  10.         elemPos  = elemPos  - pos; // play video when it is at least halfway vissible
  11.  
  12.         pausePos = elemPos + pos + elemHeight; // pause video when scroll passes the video
  13.  
  14.  
  15.         var p = document.documentElement.clientHeight;
  16.  
  17.         var check = $('.vid_pos_check').val();
  18.  
  19.         if (check == "false") {
  20.             if(p>=elemPos ){
  21.                 $('#video').trigger('play');
  22.                 $('.vid_pos_check').val('true');
  23.                 console.log('video is halfway in view so it started');
  24.             }
  25.         }
  26.  
  27.         if(check == 'true'){
  28.             if(p>=pausePos ){
  29.                 $('#video').trigger('pause');
  30.                 console.log('video out of view so it is paused');
  31.             }
  32.         }
  33.  
  34.     });
  35. });
  36. </script>
RAW Paste Data