我试图用这个线程的解决方案做到这一点:

How to make Bootstrap carousel slider use mobile left/right swipe

但是不要为我工作,这是我的代码:

<!DOCTYPE html>
<html lang="es">
  <head>
    <meta charset="utf-8">
     <link href="assets/css/bootstrap.css" rel="stylesheet">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="assets/js/jquery.mobile-1.4.5.js"></script>
    <script src="assets/js/jquery.mobile-1.4.5.min.js"></script>
   </head>
   <body>
    <section class="wrap" id="month" >
    <div id="myCarousel" class="carousel slide" data-ride="carousel">
      <!-- Indicators -->
      <ol class="carousel-indicators">
        <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
        <li data-target="#myCarousel" data-slide-to="1"></li>
        <li data-target="#myCarousel" data-slide-to="2"></li>
        <li data-target="#myCarousel" data-slide-to="3"></li>
      </ol>

      <!-- Wrapper for slides -->
      <div class="carousel-inner" role="listbox">
        <div class="item active">
          <img src="" alt="Chania">
        </div>

        <div class="item">
          <img src="" alt="Chania2">
        </div>

        <div class="item">
          <img src="" alt="Flower1">
        </div>

        <div class="item">
          <img src="" alt="Flower2">
        </div>
      </div>

      <!-- Left and right controls -->
      <a class="left carousel-control" href="#myCarousel" 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="#myCarousel" role="button" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
      </a>
    </div>
    </section>
    <script src="assets/js/bootstrap.min.js"></script>
    <SCRIPT>

        $(document).ready(function() {
           $("#myCarousel").swiperight(function() {
              $("#myCarousel").carousel('prev');
            });
           $("#myCarousel").swipeleft(function() {
              $("#myCarousel").carousel('next');
           });
        });
    </SCRIPT>
</body>

最佳答案

为什么不使用slick slider代替呢?它支持在台式机/手机上滑动。

关于javascript - 带滑动jQuery Bootstrap 3的轮播幻灯片,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38112279/

10-15 19:01