由于最近开发的项目涉及到移动端 开发,其中须要实现触屏轮播效果。然而,jquery 、bootstrap(carousel.js) 库文件并无支持触屏的事件。若是只为了实现触屏滑动这个效果引入jquerymobile的话,除了能获得本身要的结果外,还会带来意想不到的“bug”。然而本身又没去研究学习过 zepto.js。因此本身总结以下另外的二种方式 + jqm:jquery
一、下载jquerymobile库文件,导入js文件:
git
调用:swipeleft 和 swiperight 或 swipe 事件github
二、使用TouchSwipe jQuery plugin 插件 地址:https://github.com/mattbryson/TouchSwipe-Jquery-Plugin bootstrap
使用方法:学习
$("#").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)插件。 this
使用方法:spa
$('#').hammer().on('swipeleft', function(){ //$(this).carousel('next'); }); $('#').hammer().on('swiperight', function(){ //$(this).carousel('prev'); });