废话不多说直接来干货
上截图:
上代码:home.wxml
<!--swiper制作tab切换-->
<view class="tab">
<view class="tab-item {{currentTab==0?'on':''}}" bindtap="changeItem" data-current="0">平台名称</view>
<view class="tab-item {{currentTab==1?'on':''}}" bindtap="changeItem" data-current="1">平台简介</view>
<view class="tab-item {{currentTab==2?'on':''}}" bindtap="changeItem" data-current="2">平台优势</view>
</view>
<view class="content">
<swiper current="{{currentTab}}" class="swiper-box" duration="300" style="height:{{winHeight - 31}}px" bindchange="bindChange">
<swiper-item>
<text>{{text}}</text>
</swiper-item>
<swiper-item>
<text>11111111111111</text>
</swiper-item>
<swiper-item>
<text>22222222222222</text>
</swiper-item>
</swiper>
</view>
home.js
data: {
// 幻灯片
imgUrls: [
'/images/1002074.jpg',
'/images/1002074.jpg',
'/images/1002074.jpg'
],
indicatorDots: true,
autoplay: true,
interval: 3000,
duration: 1000,
// 页面配置
winWidth: 0,
winHeight: 0,
// tab切换
currentTab: 0,
},
//swiper制作tab切换
// 滑动切换tab
bindChange: function( e ) {
var that = this;
that.setData( { currentTab: e.detail.current });
},
// 点击tab切换
changeItem: function( e ) {
var that = this;
if( this.data.currentTab === e.target.dataset.current ) {
return false;
}else{
that.setData( {
currentTab: e.target.dataset.current
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
// 获取系统信息
wx.getSystemInfo({
success: function (res) {
that.setData({
winWidth: res.windowWidth,
winHeight: res.windowHeight
});
}
});
},
home.wxss
.tab{
display: flex;
margin-top:30rpx ;
width:100%;
}
.tab-item{
flex:1;
font-size:12pt ;
text-align: center;
line-height: 80rpx;
border-bottom: 9rpx solid #eee;
}
.content{
flex: 1;
}
.content>swiper{
height: 100%;
}
.tab-item.on{
color:#33a3dc;
border-bottom-color:#33a3dc ;
}