最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

最近ytkah在學習用bootstrap搭建網(wǎng)站,Bootstrap能自適應pc端和手機端,并且移動設備優(yōu)先,適合現(xiàn)如今移動營銷。bootstrap是封裝好的框架,需要某些功能只需調(diào)用相應的組件就可以,但有些還是沒加入,比如幻燈輪播觸屏左右滑動手勢就不支持,大家用的設備基本是觸屏的了,能用滑動交互在小屏幕上體驗會更好,那么如何實現(xiàn)呢?一個比較簡單的方法是增加一個滑動手勢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>

關鍵的步驟來了,我們需要寫一個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一定要對應,上面是carousel-example-generic,javascript中也要這個,否則不能實現(xiàn)。

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

  javascript命令這個是關鍵,不會寫不會改就不好玩了。做個標記,方便日后查詢

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

相關文章

最新評論

大足县| 忻州市| 图片| 杭锦后旗| 临湘市| 庆阳市| 长岛县| 中超| 新和县| 安塞县| 如皋市| 宜兴市| 高陵县| 洛扎县| 玉溪市| 岗巴县| 汨罗市| 江山市| 故城县| 双柏县| 托克逊县| 西乌| 保山市| 通榆县| 辛集市| 高唐县| 佛山市| 齐齐哈尔市| 东山县| 犍为县| 托克托县| 三穗县| 图们市| 塘沽区| 临颍县| 阳原县| 亳州市| 英德市| 邳州市| 古蔺县| 晋中市|