BootStrap实现手机端轮播图左右滑动事件
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了BootStrap实现手机端轮播图左右滑动事件,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2187字,纯文字阅读大概需要4分钟。
内容图文
用bootstrap做出的项目轮播图在手机端不能滑动,为此找了好多插件、框架。但是都不能和bootstrap良好的结合。
功夫不负有心人,经过一番查找终于在github找到了一段js:toucher.js,原文链接:https://github.com/bh-lay/toucher
由于个人水平原因代码没看懂抓狂,不过使用还是没问题滴。
第一.在head中加载toucher.js。
<script type="text/JavaScript" src="__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="__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实现手机端轮播图左右滑动事件,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
内容总结
以上是互联网集市为您收集整理的BootStrap实现手机端轮播图左右滑动事件全部内容,希望文章能够帮你解决BootStrap实现手机端轮播图左右滑动事件所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。