BootStrap实现手机端轮播图左右滑动事件
更新时间:2016年10月13日 09:11:15 投稿:mrr
用bootstrap做出的项目轮播图在手机端不能滑动,为此找了好多插件、框架。但是都不能和bootstrap良好的结合。经过一番折腾终于找到了解决方法,下面小编通过本文给大家简单介绍下
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud)
(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun)
用bootstrap做出的项目轮播图在手机端不能滑动,为此找了好多插件、框架。但是都不能和bootstrap良好的结合。
功夫不负有心人,经过一番查找终于在github找到了一段js:toucher.js,原文链接:https://github.com/bh-lay/toucher
由于个人水平原因代码没看懂抓狂,不过使用还是没问题滴。
第一.在head中加载toucher.js。
<script type="text/JavaScript" src="http://9i0i.com/pic.php?p=__PUBLIC__/home/js/toucher.js"></script>
第二.在轮播图页面实现触屏事件。
轮播图代码:
<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="http://9i0i.com/pic.php?p=__PUBLIC__/home/img/banner_01.jpg" alt="..."> <div class="carousel-caption"> ... </div> </div> <div class="item"> <img src="http://9i0i.com/pic.php?p=__PUBLIC__/home/img/banner_02.jpg" alt="..."> <div class="carousel-caption"> ... </div> </div> <div class="item"> <img src="http://9i0i.com/pic.php?p=__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实现手机端轮播图左右滑动事件,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对程序员之家网站的支持!
相关文章
JS读取XML文件数据并以table形式显示数据的方法(兼容IE与火狐)
这篇文章主要介绍了JS读取XML文件数据并以table形式显示数据的方法,涉及javascript针对xml节点操作及HTML表格操作的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下2016-06-06
最新评论