BootStrap實現(xiàn)手機端輪播圖左右滑動事件
用bootstrap做出的項目輪播圖在手機端不能滑動,為此找了好多插件、框架。但是都不能和bootstrap良好的結(jié)合。
功夫不負有心人,經(jīng)過一番查找終于在github找到了一段js:toucher.js,原文鏈接:https://github.com/bh-lay/toucher
由于個人水平原因代碼沒看懂抓狂,不過使用還是沒問題滴。
第一.在head中加載toucher.js。
<script type="text/JavaScript" src="__PUBLIC__/home/js/toucher.js"></script>
第二.在輪播圖頁面實現(xiàn)觸屏事件。
輪播圖代碼:
<div id="carousel-example-generic" class="carousel slide both" data-ride="carousel"> <!-- Indicators --> <ol class="carousel-indicators"> <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li> <li data-target="#carousel-example-generic" data-slide-to="1"></li> <li data-target="#carousel-example-generic" data-slide-to="2"></li> </ol> <!-- Wrapper for slides --> <div class="carousel-inner" role="listbox"> <div class="item active"> <img src="__PUBLIC__/home/img/banner_01.jpg" alt="..."> <div class="carousel-caption"> ... </div> </div> <div class="item"> <img src="__PUBLIC__/home/img/banner_02.jpg" alt="..."> <div class="carousel-caption"> ... </div> </div> <div class="item"> <img src="__PUBLIC__/home/img/banner_03.jpg" alt="..."> <div class="carousel-caption"> ... </div> </div> </div> <!-- Controls --> <a id="carleft" class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a id="carright" class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next"> <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> </div>
js代碼:
<script> var myTouch = util.toucher(document.getElementById('carousel-example-generic')); myTouch.on('swipeLeft',function(e){ $('#carright').click(); }).on('swipeRight',function(e){ $('#carleft').click(); }); </script>
ok手機端可以用了。
以上所述是小編給大家介紹的BootStrap實現(xiàn)手機端輪播圖左右滑動事件,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
關(guān)于JavaScript的gzip靜態(tài)壓縮方法
關(guān)于JavaScript的gzip靜態(tài)壓縮方法...2007-01-01怎樣在CocosCreator中使用物理引擎關(guān)節(jié)
這篇文章主要介紹了怎樣在CocosCreator中使用物理引擎關(guān)節(jié),對物理引擎感興趣的同學,著重要看一下2021-04-04JS讀取XML文件數(shù)據(jù)并以table形式顯示數(shù)據(jù)的方法(兼容IE與火狐)
這篇文章主要介紹了JS讀取XML文件數(shù)據(jù)并以table形式顯示數(shù)據(jù)的方法,涉及javascript針對xml節(jié)點操作及HTML表格操作的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2016-06-06