旋转木马滑动不适用于iframe视频

时间:2018-01-26 01:28:58

标签: javascript jquery html css twitter-bootstrap

我正在使用轮播滑动功能来移动幻灯片图像。当我开始移动视频部分视频开始播放而不是移动到下一个。

<div id="carousel-banner" class="carousel slide" data-ride="carousel" data-interval="false">
            <ol class="carousel-indicators">
                <li data-target="#carousel-banner" data-slide-to="0" class="active"></li>
                <li data-target="#carousel-banner" data-slide-to="1"></li>
                <li data-target="#carousel-banner" data-slide-to="2"></li>
            </ol>
            <div class="carousel-inner">
                <div class="item active">
                    <img src="img/main-banner.png" alt="">
                </div>
                <div class="item">
                    <img src="img/main-banner.png" alt="">
                </div>
                <div class="item bg-frame id='thevideo' style='display:none'">
                    <iframe width="100%" height="100%" src="https://www.youtube.com/embed/PLAI6HmLGuk?rel=0&amp;showinfo=0" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen></iframe>                       
                </div>
                <div onclick="thevid=document.getElementById('thevideo'); thevid.style.display='block'; this.style.display='none'"><img src="img/main-banner.png" style="cursor:pointer" /></div>
                </div>
            </div>
        </div>

我试过下面的carosuel脚本

$(".carousel").swipe({
      swipe: function(event, direction, distance, duration, fingerCount, fingerData) {
        if (direction == 'left') $(this).carousel('next');
        if (direction == 'right') $(this).carousel('prev');
      },
      allowPageScroll:"vertical"
    });

my demo code here

1 个答案:

答案 0 :(得分:0)

问题是iframe视频点击滑动事件。
基本上,我会尝试通过叠加和简单的j来修复它 这是一个小演示

&#13;
&#13;
/*

dependencies:

//cdnjs.cloudflare.com/ajax/libs/jquery.touchswipe/1.6.4/jquery.touchSwipe.min.js
//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js
//cdnjs.cloudflare.com/ajax/libs/jquery.touchswipe/1.6.4/jquery.touchSwipe.min.js

*/
$(".iframeSwipe").click(function() {
  $(this).removeClass("overlay");
  $("#video")[0].src += "&autoplay=1";
  $(".carousel").carousel("pause");
  event.preventDefault()
});



$(".carousel").swipe({

  swipe: function(event, direction, distance, duration, fingerCount, fingerData) {

    if (direction == 'left') $(this).carousel('next');
    if (direction == 'right') $(this).carousel('prev');

  },
  allowPageScroll: "vertical"

});
&#13;
/*
     ༼ つ ◕_◕ ༽つ

*/

.overlay::before {
  content: "";
  display: block;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  background-color: rgba(255, 255, 255, .1);
}
&#13;
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery.touchswipe/1.6.4/jquery.touchSwipe.min.js"></script>


<div class="container">

  <div class="page-header">
    <h1>Bootstrap 3 default carousel with swipe and touch gestures</h1>
    <p class="lead">How to add the swipes gesture to comand the Bootstrap 3 carousel on mobile devices.</p>
    <p>Made by <strong>Andrea Rufo</strong>, more info and tutorial on <a href="http://www.andrearufo.it/">andrearufo.it</a></p>
  </div>


  <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
      <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
      <li data-target="#carousel-example-generic" data-slide-to="1"></li>
      <li data-target="#carousel-example-generic" data-slide-to="2"></li>
      <li data-target="#carousel-example-generic" data-slide-to="3"></li>
      <li data-target="#carousel-example-generic" data-slide-to="4"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">
      <div class="item active">
        <img src="https://unsplash.it/1400/600?image=114">
      </div>
      <div class="item">
        <img src="https://unsplash.it/1400/600?image=62">
      </div>
      <div class="item">
        <img src="https://unsplash.it/1400/600?image=315">
      </div>
      <div class="item">
        <img src="https://unsplash.it/1400/600?image=622">
      </div>
      <div class="item iframeSwipe overlay">
        <iframe id="video" width="100%" height="600" src="https://www.youtube.com/embed/PLAI6HmLGuk?rel=0&amp;showinfo=0" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen></iframe>

      </div>
    </div>

    <!-- Controls -->
    <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>

</div>
&#13;
&#13;
&#13; 点击视频iframe(叠加)后,用户可以滑动并仍播放视频 希望我的回答可以帮到你:)