轮播图可以通过点击按钮来跳到上一张或者下一张,在移动端我们常用的就是通过滑动来实现一些时间,那么如何实现呢。
以下是通过bootstrap的Carousel和dropload.js(移动端上下拉动刷新插件)的实现方法。
HTML部分
<div id="goods_lunbo" style="width:200%;overflow:hidden;margin-left:-50%;">
<div id="goods_lunbo2" style="width:50%;overflow:hidden;margin:0 auto;">
<div id="carousel-example-generic0" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic0" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic0" data-slide-to="1"></li>
<li data-target="#carousel-example-generic0" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" id="carousel-inner-z" role="listBox">
<div class="item active">
<img width="100%" src="http://img04.taobaocdn.com/bao/uploaded/i4/TB1lrszIpXXXXaTXVXXXXXXXXXX_!!0-item_pic.jpg_220x220.jpg" >
<!--<div class="carousel-caption"></div>-->
</div>
<div class="item">
<img width="100%" src="http://img01.taobaocdn.com/bao/uploaded/i1/TB1RXNmHFXXXXanXFXXXXXXXXXX_!!0-item_pic.jpg_220x220.jpg" >
<!--<div class="carousel-caption"></div>-->
</div>
<div class="item">
<img width="100%" src="http://img01.taobaocdn.com/bao/uploaded/i1/TB1TjfsHVXXXXcSXVXXXXXXXXXX_!!1-item_pic.gif_220x220.jpg" >
<!--<div class="carousel-caption"></div>-->
</div>
</div>
</div>
</div>
</div>
JS部分
var carousel_=$("#carousel-example-generic0");
$("#goods_lunbo").touchwipe({
ReferenceMaterial:"#goods_lunbo2",//套的div
distance : 100,//表示滑动的距离
wipeLeftFn:function(){console.log("佐佐佐");carousel_.carousel('prev');},//向左滑动屏幕
wipeRightFn:function(){console.log("呦呦呦");carousel_.carousel('next');},//向右滑动屏幕
Nowipe:function(){}
});