swiper4实现移动端导航栏tab滑动切换

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

效果如图:

swiper4实现移动端导航栏tab滑动切换

首先引入swiper的css和js文件
官网下载地址

<link href="http://www.cppcns.com/wangluo/javascript/swiper.min.css" rel="stylesheet">
<script src="http://www.cppcns.com/wangluo/javascript/swiper.min.js"></script>

html结构部分

<body>
 <div class="tab">
 <div class="tabItem active">slider1</div>
 <div class="tabItem">slider2</div>
 </div>
 <div class="swiper-container">
 <div class="swiper-wrapper">
   <div class="swiper-slide">slider1</div>
   <div class="swiper-slide">slider2</div>
 </div>  
 </div> 
</body>

js部分

var tabItem = $('.tab .tabItem');
var mySwiper = new Swiper('.swiper-container', {
 autoplay: false,
>
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;}

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

swiper4实现移动端导航栏tab滑动切换

扫一扫手机访问