2017-09-21 14 views
0

내 비디오가 뷰포트의 초점에 들어간 후에 재생을 시작하는 방법을 찾으려고합니다. 비디오는 문서의 텍스트의 무리에있을 것이다 나는 단지 그것을동영상 시작시 초점이 맞을 때

 <script> 
    window.onload = function() { 

    // Video 
    var video = document.getElementById("video"); 

    // Buttons 
    var playButton = document.getElementById("play-pause"); 
    var playButtonImg = document.getElementById("playButtonImg"); 
    var muteButton = document.getElementById("mute"); 
    var muteButtonImg = document.getElementById("muteButtonImg"); 

    // Event listener for the play/pause button 
    playButton.addEventListener("click", function() { 
     if (video.paused == true) { 
      // Play the video 
      video.play(); 

      // Update the button text to 'Pause' 
      playButtonImg.src = "pause-sm.png"; 
     } else { 
      // Pause the video 
      video.pause(); 

      // Update the button text to 'Play' 
      playButtonImg.src = "play-sm.png"; 
     } 
    }); 

    video.addEventListener("ended", function(){ 
    playButtonImg.src = "replay-sm.png"; 
    }); 

    // Event listener for the mute button 
    muteButton.addEventListener("click", function() { 
     if (video.muted == false) { 
      // Mute the video 
      video.muted = true; 

      // Update the button text 
      muteButtonImg.src = "mute-sm.png"; 
     } else { 
      // Unmute the video 
      video.muted = false; 

      // Update the button text 
      muteButtonImg.src = "volume-sm.png"; 
     } 
    }); 

    // Pause the video when the seek handle is being dragged 
    seekBar.addEventListener("mousedown", function() { 
     video.pause(); 
    }); 
    } 
    </script> 

답변