一直覺得 bootstrap 的輪播用起來很好用,代碼簡單,又支持響應式,
但從未想過也不知道 bootstrap 的輪播竟然不支持在手機上左右滑動
解決方法就是:
使用滑動手勢 js 插件:hammer.js(百度CDN資源庫鏈接:http://cdn.code.baidu.com/)
然后在head中加載以后,通過 js 把 swipe 功能調用出來就可以了,下面是 js 命令調用 hammer.js 中的 swipe 功能代碼
<script> $(function() { var myElement = document.getElementById('carousel-example-generic') var hm = new Hammer(myElement); hm.on("swipeleft", function() { $('#carousel-example-generic').carousel('next') }) hm.on("swiperight", function() { $('#carousel-example-generic').carousel('prev') }) }) </script>