TA的每日心情 | 慵懒 2019-2-22 14:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
注册会员

- 积分
- 101
|
var wid,index;
var head_swiper = new Swiper("#headbanner",{
loop:true,
autoplay:3000,
speed:500,
autoplayDisableOnInteraction:false,
onInit: function(swiper){
wid = $(window).width()
swiper.setWrapperTranslate('-'+wid);
},
onSlideChangeEnd:function(swiper){
swiper.update()
wid = swiper.width
index = swiper.activeIndex
swiper.setWrapperTranslate('-'+index*wid);
},
onAutoplay: function(swiper){
swiper.update()
wid = swiper.width
index = swiper.activeIndex
swiper.setWrapperTranslate('-'+index*wid);
}
})
$(".icon-right").on("click",function(){
head_swiper.slideNext();//让索引增加1,但是滑动距离不正确,因此自定义滑动距离,所以这里两个滑动的api不矛盾!!!
wid = head_swiper.width
index = head_swiper.activeIndex
head_swiper.setWrapperTranslate('-'+index*wid);
})
$(".icon-left").on("click",function(){
head_swiper.slidePrev();
wid = head_swiper.width
index = head_swiper.activeIndex
head_swiper.setWrapperTranslate('-'+index*wid);
})
相对完善的一个案例,记录一下 面条代码,不懂优化,唉~ |
|