BootStrap實(shí)現(xiàn)手機(jī)端輪播圖左右滑動(dòng)事件
用bootstrap做出的項(xiàng)目輪播圖在手機(jī)端不能滑動(dòng),為此找了好多插件、框架。但是都不能和bootstrap良好的結(jié)合。
功夫不負(fù)有心人,經(jīng)過一番查找終于在github找到了一段js:toucher.js,原文鏈接:https://github.com/bh-lay/toucher
由于個(gè)人水平原因代碼沒看懂抓狂,不過使用還是沒問題滴。
第一.在head中加載toucher.js。
<script type="text/JavaScript" src="__PUBLIC__/home/js/toucher.js"></script>
第二.在輪播圖頁面實(shí)現(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手機(jī)端可以用了。
以上所述是小編給大家介紹的BootStrap實(shí)現(xiàn)手機(jī)端輪播圖左右滑動(dòng)事件,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- Bootstrap幻燈片輪播圖支持觸屏左右手勢(shì)滑動(dòng)的實(shí)現(xiàn)方法
- Bootstrap每天必學(xué)之響應(yīng)式導(dǎo)航、輪播圖
- Bootstrap開發(fā)實(shí)戰(zhàn)之響應(yīng)式輪播圖
- 使用BootStrap建立響應(yīng)式網(wǎng)頁——通欄輪播圖(carousel)
- 利用BootStrap的Carousel.js實(shí)現(xiàn)輪播圖動(dòng)畫效果
- BootStrap實(shí)現(xiàn)輪播圖效果(收藏)
- 在bootstrap中實(shí)現(xiàn)輪播圖實(shí)例代碼
- Bootstrap實(shí)現(xiàn)基于carousel.js框架的輪播圖效果
- bootstrap輪播圖示例代碼分享
- bootstrap實(shí)現(xiàn)輪播圖效果
相關(guān)文章
Bootstrap基本樣式學(xué)習(xí)筆記之按鈕(4)
篇文章主要介紹了Bootstrap學(xué)習(xí)筆記之按鈕基本樣式的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12關(guān)于JavaScript的gzip靜態(tài)壓縮方法
關(guān)于JavaScript的gzip靜態(tài)壓縮方法...2007-01-01怎樣在CocosCreator中使用物理引擎關(guān)節(jié)
這篇文章主要介紹了怎樣在CocosCreator中使用物理引擎關(guān)節(jié),對(duì)物理引擎感興趣的同學(xué),著重要看一下2021-04-04JS讀取XML文件數(shù)據(jù)并以table形式顯示數(shù)據(jù)的方法(兼容IE與火狐)
這篇文章主要介紹了JS讀取XML文件數(shù)據(jù)并以table形式顯示數(shù)據(jù)的方法,涉及javascript針對(duì)xml節(jié)點(diǎn)操作及HTML表格操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06