微场景 swiper 监测当前页数进而做其他动作

来源:互联网 发布:一键换机软件下载 编辑:程序博客网 时间:2024/06/08 15:34

var lihong = document.getElementById('interact');

var swiper = new Swiper('.swiper-container', {
    pagination: '.swiper-pagination',
    paginationClickable: true,
    watchSlidesProgress : true,
    direction: 'vertical',
    onInit: function(swiper){ //Swiper2.x的初始化是onFirstInit
      swiperAnimateCache(swiper); //隐藏动画元素 
      swiperAnimate(swiper); //初始化完成开始动画
    }, 
    onSlideChangeEnd: function(swiper){ 
   
      swiperAnimate(swiper); //每个slide切换结束时也运行当前slide动画
      if (swiper.realIndex>0) {
      alert(swiper.activeIndex)
      lihong.setAttribute('style','display:block');
}else{
lihong.setAttribute('style','display:none');
};
    } 

});



swiper.realIndex 当前是第几页(从0开始),配合onSlideChangeEnd做判断完成一些事情。

*swiper的回调函数onSlideChangeEnd 这个函数可以在slide切换结束时做很多动作。

原创粉丝点击