swiper动态改变滑动内容的实现方法
2018-01-17 11:39
721 查看
假设当前显示的是1,往左滑动一个递减1,往右滑动一个递增1
body下面添加如下代码
<div class="swiper-container temp"> <div class="swiper-wrapper"> <div class="swiper-slide"> 1 </div> <div class="swiper-slide"> 2 </div> <div class="swiper-slide"> 3 </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; }, }, })
初始值:
往左滑动三次:
往右滑动一次
做这个测试主要为了后面日历的左右滑动改变上一月下一月
总结
以上所述是小编给大家介绍的swiper动态改变滑动内容的实现方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
您可能感兴趣的文章:
相关文章推荐
- 动态改变DataWindow控件窗口中内容的几种实现方法
- 动态改变DataWindow控件窗口中内容的几种实现方法
- 轮播组件Swiper实现移动端网站的内容触摸滑动使用方法
- 动态改变DataWindow控件窗口中内容的几种实现方法
- swiper动态改变滑动内容
- 动态改变DataWindow控件窗口中内容的几种实现方法
- input文本框没有onchange事件,可以通过下面两种方法实现当input内容改变时触发事件
- 实现Web页面内容动态改变的dhtml操作
- 策略设计模式:父类持有接口成员变量,动态设定接口成员实现类,动态改变方法
- 超棒的JS移动设备滑动内容幻灯实现 - Swiper
- 超棒的JS移动设备滑动内容幻灯实现 - Swiper
- javascript实现框架高度随内容改变的方法
- 用js实现层随着内容大小动态渐变改变 推荐
- javascript实现框架高度随内容改变的方法
- 实现可动态改变宽度的表格简单方法
- javascript实现动态改变层大小的方法
- JavaScript实现点击单选按钮改变输入框中文本域内容的方法
- JavaScript动态改变div属性的实现方法
- 超棒的JS移动设备滑动内容幻灯实现 - Swiper
- JavaScript动态改变div属性的实现方法