亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Bootstrap幻燈片輪播圖支持觸屏左右手勢滑動的實(shí)現(xiàn)方法

 更新時(shí)間:2016年10月13日 09:23:10   作者:ytkah  
最近在研究用bootstrap搭建網(wǎng)站,Bootstrap能自適應(yīng)pc端和手機(jī)端,并且移動設(shè)備優(yōu)先,適合現(xiàn)如今移動營銷,大家用的設(shè)備基本是觸屏的了,能用滑動交互在小屏幕上體驗(yàn)會更好,那么如何實(shí)現(xiàn)呢?下面小編給大家介紹下bootstrap 手勢滑動輪播圖的實(shí)現(xiàn)方法

最近ytkah在學(xué)習(xí)用bootstrap搭建網(wǎng)站,Bootstrap能自適應(yīng)pc端和手機(jī)端,并且移動設(shè)備優(yōu)先,適合現(xiàn)如今移動營銷。bootstrap是封裝好的框架,需要某些功能只需調(diào)用相應(yīng)的組件就可以,但有些還是沒加入,比如幻燈輪播觸屏左右滑動手勢就不支持,大家用的設(shè)備基本是觸屏的了,能用滑動交互在小屏幕上體驗(yàn)會更好,那么如何實(shí)現(xiàn)呢?一個(gè)比較簡單的方法是增加一個(gè)滑動手勢js插件:hammer.js,網(wǎng)上有很多cdn調(diào)用地址,像//cdn.bootcss.com/hammer.js/2.0.8/hammer.min.js,我們在head中加載一下然后再通過javascript把swipe功能調(diào)用出來就可以了。下面是幻燈片的原始html代碼

<div data-ride="carousel" class="carousel slide" id="carousel-example-generic">
<ol class="carousel-indicators">
<li class="" data-slide-to="0" data-target="#carousel-example-generic"></li>
<li data-slide-to="1" data-target="#carousel-example-generic" class="active"></li>
<li data-slide-to="2" data-target="#carousel-example-generic" class=""></li>
</ol>
<div role="listbox" class="carousel-inner">
<div class="item">
<img alt="First slide" src="http://ibootstrap-file.b0.upaiyun.com/lorempixel.com/1600/500/sports/1/default.jpg" data-holder-rendered="true">
</div>
<div class="item active">
<img alt="Second slide [1140x500]" src="http://ibootstrap-file.b0.upaiyun.com/lorempixel.com/1600/500/sports/2/default.jpg" data-holder-rendered="true">
</div>
<div class="item">
<img alt="Third slide [1140x500]" src="http://ibootstrap-file.b0.upaiyun.com/lorempixel.com/1600/500/sports/3/default.jpg" data-holder-rendered="true">
</div>
</div>
<a data-slide="prev" role="button" href="#carousel-example-generic" class="left carousel-control">
<span aria-hidden="true" class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a data-slide="next" role="button" href="#carousel-example-generic" class="right carousel-control">
<span aria-hidden="true" class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>

關(guān)鍵的步驟來了,我們需要寫一個(gè)javascript命令調(diào)用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>

  div的id一定要對應(yīng),上面是carousel-example-generic,javascript中也要這個(gè),否則不能實(shí)現(xiàn)。

  需要注意的是,jquery版本最好是1.9版本的jquery-1.9.1.min.js,否則可能在電腦上可以實(shí)現(xiàn)手勢滑動,而在手機(jī)上無法觸摸滑動

  javascript命令這個(gè)是關(guān)鍵,不會寫不會改就不好玩了。做個(gè)標(biāo)記,方便日后查詢

以上所述是小編給大家介紹的Bootstrap幻燈片輪播圖支持觸屏左右手勢滑動的實(shí)現(xiàn)方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論