swiper4移动端导航栏tab滑动切换效果,供大家参考,具体内容如下

效果如图:

c4ae82112f5d69035cfeb5c04210e0bc.gif

首先引入swiper的css和js文件

官网下载地址

html结构部分

slider1
slider2
slider1
slider2

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;}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐