为什么这个 Bootstrap Carousel 滑动功能对我不起作用? [英] Why won't this Bootstrap Carousel swipe function work for me?

查看:29
本文介绍了为什么这个 Bootstrap Carousel 滑动功能对我不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了这个代码笔:https://codepen.io/andrearufo/pen/rVWpyE

而且我很想使用它,但由于某种原因它对我不起作用,即使我复制它而不更改任何内容.这是为什么?

我没有忘记嵌入 bootstrap 和 jquery.

我还尝试了其他用于滑动功能的解决方案,但由于某种原因,它们都不起作用.唯一可以滑动的旋转木马(我曾在 Google Chrome 开发者工具中尝试过)在这个 codepen 上.

$(".carousel").swipe({滑动:功能(事件,方向,距离,持续时间,fingerCount,fingerData){if (direction == 'left') $(this).carousel('next');if (direction == 'right') $(this).carousel('prev');},allowPageScroll:"垂直"});

<div class="page-header"><h1>带有滑动和触摸手势的 Bootstrap 默认轮播</h1><p class="lead">如何在移动设备上添加滑动手势以命令 Bootstrap 轮播.</p><p>由 <strong>Andrea Rufo</strong> 制作,有关 <a href="http://www.orangedropdesign.com/"> 的更多信息和教程OrangeDropDesign.com</a></p>

<div id="carousel-example-generic" class="carousel slide" data-ride="carousel"><!-- 指标--><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><!-- 幻灯片包装器--><div class="carousel-inner" role="listbox"><div class="item active"><img src="https://unsplash.it/1400/600?image=114">

<div class="item"><img src="https://unsplash.it/1400/600?image=745">

<div class="item"><img src="https://unsplash.it/1400/600?image=315">

<div class="item"><img src="https://unsplash.it/1400/600?image=622">

<div class="item"><img src="https://unsplash.it/1400/600?image=401">

<!-- 控件--><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">上一个</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">下一步</span></a>

解决方案

以下是您可能会错过 JQuerySwipe LIB 的示例.

$(".carousel").swipe({滑动:功能(事件,方向,距离,持续时间,fingerCount,fingerData){if (direction == 'left') $(this).carousel('next');if (direction == 'right') $(this).carousel('prev');},allowPageScroll:"垂直"});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><!-- 最新编译和缩小的 CSS --><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz"crossEuK6ys><!-- 可选主题--><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPmgJponys"cross.><!-- 最新编译和缩小的 JavaScript --><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7"cross<script src="//cdnjs.cloudflare.com/ajax/libs/jquery.touchswipe/1.6.4/jquery.touchSwipe.min.js"></script><div id="carousel-example-generic" class="carousel slide" data-ride="carousel"><!-- 指标--><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><!-- 幻灯片包装器--><div class="carousel-inner" role="listbox"><div class="item active"><img src="https://unsplash.it/1400/600?image=114">

<div class="item"><img src="https://unsplash.it/1400/600?image=315">

<div class="item"><img src="https://unsplash.it/1400/600?image=622">

<div class="item"><img src="https://unsplash.it/1400/600?image=401">

<!-- 控件--><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">上一个</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">下一步</span></a>

I found this codepen: https://codepen.io/andrearufo/pen/rVWpyE

and I'd love to use it, but for some reason it won't work for me, even if I copy it without changing a single thing. Why is this?

I haven't forgotten to embed bootstrap nor jquery.

I've also tried other solutions for a swipe function, but for some reason none of them worked. The only carousel where the swipe worked (I've tried in Google Chrome developer tools) was on this codepen.

$(".carousel").swipe({

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

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

  },
  allowPageScroll:"vertical"

});

<div class="container">
  
  <div class="page-header">
    <h1>Bootstrap default carousel with swipe and touch gestures</h1>
    <p class="lead">How to add the swipes gesture to comand the Bootstrap carousel on mobile devices.</p>
    <p>Made by <strong>Andrea Rufo</strong>, more info and tutorial on <a href="http://www.orangedropdesign.com/"> OrangeDropDesign.com</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=745">
      </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">
        <img src="https://unsplash.it/1400/600?image=401">
      </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>

解决方案

Here is the example you might miss JQuery or Swipe LIB.

$(".carousel").swipe({

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

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

  },
  allowPageScroll:"vertical"

});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery.touchswipe/1.6.4/jquery.touchSwipe.min.js"></script>
<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=315">
      </div>
      <div class="item">
        <img src="https://unsplash.it/1400/600?image=622">
      </div>
      <div class="item">
        <img src="https://unsplash.it/1400/600?image=401">
      </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>

这篇关于为什么这个 Bootstrap Carousel 滑动功能对我不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆