简体   繁体   English

jQuery:在引导程序滑块中播放视频

[英]Jquery : Play video in bootstrap slider

i want to play video when item gets active class in bootstrap slider below is my code 我想在下面的引导程序滑块中的项目成为活动类时播放视频是我的代码

<div class="item" id='mobileapp'>
  <video loop controls width="100%" id='video'>
    <source src="../../vid.mp4" width="100%" height="100%" type="video/mp4"> Your browser does not support the video tag.
  </video>    
  <div class="overlay"></div>
  <div class="carousel-caption">
    <h1 class="super-heading text-white">Heading</h1>
    <div class='row'>
      <div class='col-sm-2 col-sm-offset-1'>
        <img src='../img/googleplay.png' class='img-responsive hidden-xs' />
      </div>   
      <div class='col-sm-2'>
        <img src='../img/applestore.png' class='img-responsive hidden-xs' />
      </div>
    </div>   
  </div>
</div>

Js JS

<script>
  $(document).ready(function () {

    if ($('#mobileapp').hasClass('active')) {
      $('#video')[0].play();
    }
    else {
      $('#video')[0].pause();
    }

  })
</script>

active class gets added but it does not pay video 活动班级被添加,但不支付视频

the functions 'play' and 'pause' are not jquery functions, they belong to the DOM element. 函数“播放”和“暂停”不是jquery函数,它们属于DOM元素。 Now to make it work try to execute your code every 10 miliseconds or something like that. 现在要使其工作,请尝试每10毫秒或类似的时间执行一次代码。 Try: 尝试:

 var videoElt = document.getElementById('video'); $(document).ready(function () { setInterval(function () { if ($('#mobileapp').hasClass('active')) { videoElt.play(); // to play the video } else { videoElt.pause(); // to pause the video } }, 10); }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM