【问题标题】:Swipe left/right for MOBILE on Bootstrap 3 Carousel在 Bootstrap 3 Carousel 上向左/向右滑动 MOBILE
【发布时间】:2019-02-07 23:33:06
【问题描述】:

我尝试使用 jquery 向 Bootstrap Carousel Slider 添加向左/向右滑动,但它不起作用。这是我的代码:

<div class="container">

  <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="">
      </div>
      <div class="item">
        <img src="">
      </div>
      <div class="item">
        <img src="">
      </div>
      <div class="item">
        <img src="">
      </div>
      <div class="item">
        <img src="">
      </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>  

Javascript:

$(".carousel").swipe({

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

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

  },
  allowPageScroll:"vertical"

});

我想补充一点,我也尝试使用官方页面上的 jquery 移动脚本:

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> 

无论如何我都尝试过滑动图像不起作用。 我在页面上使用的脚本:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

【问题讨论】:

标签: javascript jquery html twitter-bootstrap jquery-mobile


【解决方案1】:

使用 javascript 启用它:

$("#carousel-example-generic").carousel();

$(".item").click(function(){
$("#carousel-example-generic").carousel(1);
});

$(".left carousel-control").click(function(){
$("#carousel-example-generic").carousel("prev");
});

$(".right carousel-control").click(function(){
    $("#carousel-example-generic").carousel("next");
    });

【讨论】:

  • 抱歉,我忘记写出我正在使用的 javascript 代码。我也试过你的代码,但没有结果:(
  • 它不起作用,即使您的代码编辑。你知道这个问题的任何其他解决方案吗?无论如何谢谢。
  • 它工作正常,检查链接:(w3schools.com/code/tryit.asp?filename=FUWDWVQCD2RX)
  • 是的,它有效,但我需要在移动设备上滑动以查看轮播,而不仅仅是使用箭头或项目符号。
猜你喜欢
  • 2015-05-27
  • 2012-12-17
  • 2013-10-27
  • 1970-01-01
  • 1970-01-01
  • 2013-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多