0

how I can make the close-btn close the video and stop it in same time?? the close-btn close the video but the sound still run in background?? do I have any probleme in the code?

<HTMl>
  <head>
      <link rel="stylesheet" href="style.css">
  </head>
<body>
  
<div class="video-player" id="video-player">
<video width="100%" controls autoplay id="myVideo">
  <source src="media/vid1.mp4" type="video/mp4">
</video>
   <img src="media/close.png" class="close-btn"
    onclick="stopVideo()">
</div>


<script>

var Videoplayer = document.getElementById("videoPlayer");
var Videoplayer = document.getElementById("myVideo");

function stopVideo(){

  videoPlayer.style.display = "none";
}

</script>

David784
  • 7,031
  • 2
  • 22
  • 29
El KA
  • 1
  • Does this answer your question? [Javascript to stop HTML5 video playback on modal window close](https://stackoverflow.com/questions/5958132/javascript-to-stop-html5-video-playback-on-modal-window-close) – David784 Dec 26 '21 at 17:52
  • There are some inconsistencies with your code; `Videoplayer` and `videoPlayer` being capitalized differently. But the main thing is that you arent' stopping the video, just hiding it. – Emiel Zuurbier Dec 26 '21 at 17:59
  • you need to stop the video `videoPlayer.pause()` not just hide it visually – Offbeatmammal Dec 27 '21 at 11:54

0 Answers0