ITPub博客

首页 > IT职业 > IT生活 > 让Bootstrap轮播插件carousel支持左右滑动手势的三种方法

让Bootstrap轮播插件carousel支持左右滑动手势的三种方法

IT生活 作者:maggiefengyu 时间:2021-09-09 08:57:05 0 删除 编辑

因为最近开发的项目涉及到移动设备上的 HTML5 开发,其中需要实现轮播效果。然后最快捷的方式,你知道的(Bootstrap),然后原生的 Bootstrap 的 carousel.js 插件并没有支持手势。

然后......自己想办法呗,再然后,就有下面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。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/925/viewspace-2798065/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    68
  • 访问量
    581