模态HTML 5视频静音关闭?

时间:2016-01-30 14:01:49

标签: javascript jquery html

我有一个以模态播放的视频然而当你关闭它时,声音会继续在后台播放。我想知道当模态关闭时是否有办法暂停视频?我正在使用Materialise库。



<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.96.1/css/materialize.min.css">

<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.96.1/js/materialize.min.js"></script>

<div class="card-panel">
  <div class="row center">
    <h1>Welcome to project Husky!</h1>
    <h5><span class="element"></span></h5>
    <a class="modal-trigger waves-effect waves-light btn" href="#modal3">Modal</a>
  </div>

  <!-- Modal Structure -->

  <div id="modal3" class="modal modal-fixed-footer">
    <div class="modal-content">
      <div class="row center">
        <video width="900" controls>
          <source src="videos/husky.mp4" type="video/mp4">
            <source src="mov_bbb.ogg" type="video/ogg">
              Your browser does not support HTML5 video.
        </video>
           <script>

    $('#modal3').closeModal();
   function pauseVid() {
       vid.pause();
   }
        </script>
      </div>
    </div>
    <div class="modal-footer">
      <a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat ">Agree</a>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

MCEV:

     <script>

    $('#modal3').closeModal();
    $('videos/husky.mp4').get(0).pause();
        </script>

1 个答案:

答案 0 :(得分:2)

jQuery对象上不存在pause()方法;它位于底层DOM元素上,因此您需要使用以下任一方法暂停视频:

$('video')[0].pause();

$('video').get(0).pause();