swiper插件(触碰图片之后停止轮播)

 

移动端轮播:swiper插件(触碰图片之后停止轮播)

标签: 移动端轮播swiper触碰后停止
 分类:

下面是我遇到的问题,也是用此插件常用的几个参数,如果你的轮播不需要很复杂,看本文就可以解决。假如你想多了解些, 看官们这里请swiper 插件的官方地址。

第一步 引入 swiper.min.js

<script src="../style/js/swiper.min.js"></script>
  • 1
  • 1

第二步 html

<div class="swiper-container">
    <div class="swiper-wrapper">
        <div class="swiper-slide">
            <img alt="" src="http://wx.okair.net/wxpic/wxb2c/indexpage/index_banner1.jpg">
        </div>
        <div class="swiper-slide">
            <img alt="" src="http://wx.okair.net/wxpic/wxb2c/indexpage/index_banner2.jpg">
        </div>
        <div class="swiper-slide">
            <img alt="" src="http://wx.okair.net/wxpic/wxb2c/indexpage/index_banner3.jpg">
        </div>
    </div>
    <div class="swiper-pagination"></div> <!--需要轮播序号的时候写-->
</div>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

第三步 调用 ( 重点来了 )

var mySwiper = new Swiper('.swiper-container', {
        pagination : '.swiper-pagination',
        loop : true,
        autoplay : 3000
});
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

现在这种情况下,图片可以自动轮播,但是当用手触碰之后,就会停止轮播,所以要再添加一个参数

var mySwiper = new Swiper('.swiper-container', {
        pagination : '.swiper-pagination',
        loop : true,
        autoplay : 3000,
        autoplayDisableOnInteraction : false      /*设置成false 注意此参数,默认为true */ 
});

1

2

  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

无论怎么滑,轮播事件都会重新触发。

posted @ 2017-08-18 16:00  szchenrong  阅读(89)  评论(0)    收藏  举报