swiper动态改变滑动内容
假设当前显示的是1,往左滑动一个递减1,往右滑动一个递增1
body下面添加如下代码
<div class="swiper-container temp"> <div class="swiper-wrapper"> <div class="swiper-slide"></div> <div class="swiper-slide"></div> <div class="swiper-slide"></div> </div> </div>
引用swiper的css和js脚本(当前使用的是4.x以上版本)
添加js脚本
var now_ActiveIndex=2;//,//当前所在下标 var tempSwiper = new Swiper('.swiper-container.temp', { initialSlide: 1, loop:true, speed:400, on: { slideChange: function(swiper){//当当前Slide切换时执行(activeIndex发生改变) var pre_number=Number($(this.slides[now_ActiveIndex]).text()); if(now_ActiveIndex>this.activeIndex){ if(now_ActiveIndex==4&&this.activeIndex==1){ $(this.slides[this.activeIndex]).text(pre_number); }else{//上一个 var act_number=pre_number-1; $(this.slides[this.activeIndex]).text(act_number); } }else if(now_ActiveIndex<this.activeIndex){ if(now_ActiveIndex==0&&this.activeIndex==3){ $(this.slides[this.activeIndex]).text(pre_number); }else{//下一个 var act_number=pre_number+1; $(this.slides[this.activeIndex]).text(act_number); } } now_ActiveIndex=this.activeIndex; }, }, })
初始值:
往左滑动三次:
往右滑动一次
做这个测试主要为了后面日历的左右滑动改变上一月下一月
相关推荐
骆驼的自白 2020-07-05
82244951 2020-06-28
zengni 2020-05-14
ELEMENTS爱乐小超 2020-05-07
资源分享 2020-01-21
SIMONDOMAIN 2020-01-05
gjcxywwx 2019-11-04
zhangyusng 2018-03-03
dongnaosenlu 2018-09-27
学而思之 2018-09-27
ThikHome 2019-07-01
小傻 2019-06-28
zyytaiyame 2019-06-28
hzwinner 2019-06-27
cc工作学习有感 2019-06-27
云端漂移 2019-06-27
konghouy 2019-06-21
堇年 2019-06-21