3 HTML5 видео в модальности, но только 1 останавливается и перезапускается при закрытии - PullRequest
0 голосов
/ 28 декабря 2018

Ниже приведен мой код HTML, CSS и JavaScript, который я использовал для создания модального стиля.Событие onclick работает только для одного модального, а не для двух других.Мне нужно, чтобы видео остановилось и перезапустилось после закрытия модального окна.Это должно происходить для каждого мода, когда они закрыты.Остановка и перезапуск видео либо для первого, либо для последнего видео, но мне нужно, чтобы он работал для всех 3 видео.

HTML

<!----Video Modals--->
<input class="modal-state" id="emailModal" type="checkbox" />
<div class="modal">
  <label onclick="stop_and_restart()"  class="modal__bg" for="emailModal" ></label>
  <div class="modal__inner">
    <label onclick="stop_and_restart()" class="modal__close" for="emailModal"></label>
    <h2></h2>
    <p style="text-align:center"><video id="video" width="624px" height="352px" controls >
  <source src="video.mp4" type="video/mp4">
  <source src="video.webm" type="video/webm">
  Your browser does not support HTML5 video. 
</video></p>
  </div>
</div>
<!--- Video - 2--->
<input class="modal-state" id="dashboardModal" type="checkbox" />
<div class="modal">
  <label onclick="stop_and_restart()"  class="modal__bg" for="dashboardModal"  ></label>
  <div class="modal__inner">
    <label onclick="stop_and_restart()"  class="modal__close" for="dashboardModal"></label>
    <h2></h2>
    <p style="text-align:center"><video id="video" width="624px" height="352px" controls >
  <source src="video.mp4" type="video/mp4">
  <source src="video.webm" type="video/webm">
  Your browser does not support HTML5 video. 
</video></p>
  </div>
</div>
<!--- Video - 3 --->
<input class="modal-state" id="calendarModal" type="checkbox" />
<div class="modal">
  <label onclick="stop_video1()" class="modal__bg" for="calendarModal" ></label>
  <div class="modal__inner">
    <label onclick="stop_video1()" class="modal__close" for="calendarModal"></label>
    <h2></h2>
    <p style="text-align:center"><video id="video" width="624px" height="352px" controls >
  <source src="video.mp4" type="video/mp4">
  <source src="video.webm" type="video/webm">
  Your browser does not support HTML5 video. 
</video></p>
  </div>
</div>
<!---Video Modals - End --->

CSS -

.modal-mask {
  position: fixed;
  z-index: 9998;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, .5);
  display: table;
  transition: opacity .3s ease;
}

.modal-wrapper {
  display: table-cell;
  vertical-align: middle;
}

.modal-container {
  width: 640px;
  margin: 0px auto;
  padding: 15px;
  background-color: #fff;
  border-radius: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .33);
  transition: all .3s ease;
  font-family: Helvetica, Arial, sans-serif;
}

@media screen and (max-width: 640px) {
    .modal-container {
    width: 100%;
    }
}


.modal-header h3 {
  margin-top: 0;
  color: #42b983;
}

.modal-body {
  margin: 20px 0;
}

.modal-default-button {
    background: transparent;
    border: none;
    font-size: 24px; 
      margin: 10px;
        float:right;
      color: #aaa;
}



.modal-enter {
  opacity: 0;
}

.modal-leave-active {
  opacity: 0;
}

.modal-enter .modal-container,
.modal-leave-active .modal-container {
  -webkit-transform: scale(1.1);
  transform: scale(1.1);
}

JavaScript -

 var vid = document.getElementById("video");
   function stop_and_restart() {
    vid.pause();
    vid.currentTime=0;
    } 
...