swiper4移动端导航栏tab滑动切换效果,供大家参考,具体内容如下
效果如图:
首先引入swiper的css和js文件
官网下载地址
html结构部分
slider1slider2slider1slider2
js部分
var tabItem = $('.tab .tabItem');
var mySwiper = new Swiper('.swiper-container', {
autoplay: false,
on:{
//swiper从当前slide开始过渡到另一个slide时执行
slideChangeTransitionStart: function(){
var n = this.activeIndex;//过渡后的slide索引
changeTab(n);
}
}
})
//tab点击切换silde
tabItem.click(function(){
var ind = $(this).index();
changeTab(ind);
mySwiper.slideTo(ind);
})
//tab切换样式
function changeTab(index){
tabItem.removeClass('active').eq(index).addClass('active');
}
css部分
html,body{width: 100%;height: 100%;}
div{margin: 0;padding: 0;}
.swiper-container,.swiper-wrapper,.swiper-slide{width: 100%;height: 100%;}
.swiper-slide{display: flex;align-items: center;justify-content: space-around;}
.tab{width: 100%;height: 50px;overflow: hidden;border-bottom: 1px solid #eee;position: fixed;top: 0;left: 0;z-index: 999;}
.tabItem{width: 50%;height: 50px;float: left;background: #e5e5e5;line-height: 50px;text-align: center;}
.active{background: #FE2D26;}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
时间: -10-13