Create Touch-enabled Bootstrap 4/3 Carousel With Swipe Carousel

Create Touch-enabled Bootstrap 4/3 Carousel With Swipe Carousel
File Size: 78.9 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

Swipe Carousel is a jQuery plugin to create mobile-friendly Bootstrap carousels by adding smart touch support to the native Bootstrap 4 or Bootstrap 3 carousel component.

With this plugin, the users are able to navigation between carousel slides by swiping on the mobile devices.

How to use it:

1. Create a Bootstrap carousel on the page following the markup structure like this:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<div id="carouselExampleIndicators" class="carousel slide my-carousel" data-ride="carousel">
  <ol class="carousel-indicators">
    <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
  </ol>
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img class="d-block w-100" src="https://picsum.photos/1920/1080/?random" alt="First slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src="https://picsum.photos/1921/1080/?random" alt="Second slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src="https://picsum.photos/1922/1080/?random" alt="Third slide">
    </div>
  </div>
  <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

2. Download and include the JavaScript file bootstrap-swipe-carousel.min.js after Bootstrap JS.

<script src="dist/bootstrap-swipe-carousel.min.js"></script>

3. Initialize the Swipe Carousel plugin and done.

$('.my-carousel').carousel().swipeCarousel({
  // options here
});

4. Set the swipe sensitivity.

$('.my-carousel').carousel().swipeCarousel({
  // low, medium or high
  sensitivity: 'high' 
});

5. You can also implement the Swipe Carousel as an ES6 module.

# NPM
$ npm install swipe-carousel --save
import $ from 'jquery';
import bootstrap from 'bootstrap';
import BootstrapSwipeCarousel from 'smart-bootstrap-swipe-carousel';

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