---
title: "让Bootstrap轮播插件carousel支持左右滑动手势的三种方法"
author: "gohands"
date: "2016-03-02T20:43:46Z"
tags: []
categories: ["Web前端"]
slug: "bootstrap-carousel"
draft: false
lastmod: "2016-03-02T20:47:58Z"
id: 2280098
url: "https://gohands.iteye.com/blog/2280098"
---

因为最近开发的项目涉及到移动设备上的 HTML5 开发，其中需要实现左右滑动的轮播效果。网上看到下面3种解决方案 ,准备后面试试看效果如何：

jQuery Mobile (http://jquerymobile.com/download/)

 $("#carousel-generic").swipeleft(function() {

  $(this).carousel('next');

 });

$("#carousel-generic").swiperight(function() {

  $(this).carousel('prev');

 });

TouchSwipe jQuery plugin (https://github.com/mattbryson/TouchSwipe-Jquery-Plugin)

 $("#carousel-generic").swipe({

  swipeLeft: function() { $(this).carousel('next'); },

  swipeRight: function() { $(this).carousel('prev'); },

 });

hammer.js (http://eightmedia.github.io/hammer.js/) +

jquery.hammer.js (https://github.com/EightMedia/jquery.hammer.js)

 $('#carousel-generic').hammer().on('swipeleft', function(){

  $(this).carousel('next');

 });

$('#carousel-generic').hammer().on('swiperight', function(){

  $(this).carousel('prev');

 });

单单为了支持滑动手势而导入整个 jQuery Mobile 貌似有些大材小用， 而 TouchSwipe 在两边可点击按钮区域滑动无效，然后选择了 Hammer。

英文原文： [http://lazcreative.com/blog/adding-swipe-support-to-bootstrap-carousel-3-0/](http://lazcreative.com/blog/adding-swipe-support-to-bootstrap-carousel-3-0/)