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.
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 availablehere 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).
|
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.*
|
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.
|
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.
|
What is bootstrap and why should you use bootstrap?
ReplyDeleteYou stole this article from : http://lazcreative.com/blog/adding-swipe-support-to-bootstrap-carousel-3-0/
ReplyDeleteIt’s hard to search out educated people on this topic, but you sound like you realize what you’re talking about! Thanks PSD to Wordpress
ReplyDelete