Smooth Touch-enabled Carousel with jQuery and Bootstrap

Smooth Touch-enabled Carousel with jQuery and Bootstrap
File Size: 6.33 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

Bootstrap Carousel Swipe is a small jQuery plugin which adds HTML5 touch events support to native Bootstrap carousel component for better mobile compatible.

How to use it:

1. Create a carousel following the markup structure introduced in Bootstrap's carousel document.

<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>
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
    <div class="item active">
      <img src="..." alt="...">
      <div class="carousel-caption">
        ...
      </div>
    </div>
    <div class="item">
      <img src="..." alt="...">
      <div class="carousel-caption">
        ...
      </div>
    </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>

2. Download and include the Bootstrap Carousel Swipe plugin after jQuery JavaScript library.

<script src="/path/to/jquery.min.js"></script> 
<script src="/path/to/bootstrap.min.js"></script> 
<script src="/path/to/carousel-swipe.js"></script> 

3. Initialize the carousel plugin and done.

$(".carousel").carousel();

4. Change the swipe sensitivity.

$(".carousel").carousel({

  // percent-per-second
  // default is 50
  // false = disable touch swipe
  swipe: 30
  
});

Change log:

2017-08-25

  • Prevent swiping while sliding

2016-05-28

  • Stop any event while the transition is happening

This awesome jQuery plugin is developed by avinoamr. For more Advanced Usages, please check the demo page or visit the official website.