LazCreative

browse posts by date by category by tag view all

written by


Adding swipe support to Bootstrap Carousel 3.0

August 21, 2013 | filed in Blog, Code, How To | Test

With the release of bootstrap version 3, I thought it would be a good time to review my previous post on adding swipe support to bootstraps carousel and verify that everything still works as expected. After a quick wire up with a custom jQuery mobile and downloading all of the new bootstrap components I was pleased to see that nothing from my previous example was broken.

Things have changed a bit however in the year since my previous post. Newer libraries are available, different plugins, the carousel itself has some additional features such as indicators. Instead of simply updating my previous post with the new info, I thought I might delve into some of the more common questions that were asked in my previous posts and show how to do the wireups in a few of the other common touch libraries.

If you’re looking for code explanation, this post isn’t for you, refer to my previous post on this subject.

Without any further ado here are some other examples of adding swipe support to bootstraps carousel.

Adding swipe support with jQuery Mobile.

Unless you need the entire library I recommend that you build a custom version available here select the “touch” checkbox under events, the current minified version of that for version 1.3.2 is below (jquery.mobile.custom.min.js)

Include this as a separate file in your document source and then add the following script to enable touch support within carousel (note that #myCarousel should match the ID or class of the carousel you’re attempting to bind to).


Here is a functioning demo of the jQuery Mobile example

Adding with TouchSwipe plugin

If you don’t want to use jQuery Mobile or are having issues with it, TouchSwipe is another jQuery option for you TouchSwipe Plugin download this and include it in your project. To wire up support for carousel add the following script. *Thanks to Eric for the slide indicator fix here.*


Here is a functioning demo of the TouchSwipe example

Adding support with Hammer.js

Hammer.js is designed to be a straight Javascript alternative, however Bootstrap’s carousel uses jQuery so you’ll be loading that library anyway. Hammer does work with jQuery through. Grab a copy of it Hammer.js then add the following script to your page.


Here is a functioning demo of the Hammer example.

Which one should I use?

That’s easy, use the one that fits your project requirements the best. Seriously. Each and every one of these libraries is under 5k minified and gzipped (unless you’re going with the full jQuery.Mobile library). Choose the one that’s the easiest for you to work with.

How do I add swipe support for more than one carousel on a page?

Adding more swipe support for more than one slider is very simple. Change your script to include additional targets. The script below is for jQuery mobile just modify it to fit the library you need.

Have something to add? Feel free to leave a comment below.

Happy Coding.