这篇文章主要介绍了微信小程序 swiper制作tab切换实现代码的相关资料,需要的朋友可以参考下
微信小程序 swiper制作tab切换
实现效果图:
swiper制作tab切换
index.html
<view class="swiper-tab">
<view class="swiper-tab-list {{currenttab==0 ? 'on' : ''}}" data-current="0" bindtap="swichnav">seside1</view>
<view class="swiper-tab-list {{currenttab==1 ? 'on' : ''}}" data-current="1" bindtap="swichnav">seside2</view>
<view class="swiper-tab-list {{currenttab==2 ? 'on' : ''}}" data-current="2" bindtap="swichnav">seside3</view>
</view>
<swiper current="{{currenttab}}" class="swiper-box" duration="300" style="height:{{winheight - 31}}px" bindchange="bindchange">
<swiper-item>
<view>seside1</view>
</swiper-item>
<swiper-item>
<view>seside2</view>
</swiper-item>
<swiper-item>
<view>seside3</view>
</swiper-item>
</swiper>
index.css
.swiper-tab{
width: 100%;
border-bottom: 2rpx solid #777777;
text-align: center;
line-height: 80rpx;
}
.swiper-tab-list{
font-size: 30rpx;
display: inline-block;
width: 20%;
color: #777777;
}
.on{
color: #da7c0c;
border-bottom: 5rpx solid #da7c0c;
}
.swiper-box{
display: block;
height: 100%;
width: 100%;
overflow: hidden;
}
.swiper-box view{
text-align: center;
}
index.js
//index.js
//获取应用实例
var app = getapp()
page( {
data: {
// 页面配置
winwidth: 0,
winheight: 0,
// tab切换
currenttab: 0,
},
onload: function() {
var that = this;
// 获取系统信息
wx.getsysteminfo( {
success: function( res ) {
that.setdata( {
winwidth: res.windowwidth,
winheight: res.windowheight
});
}
});
},
// 滑动切换tab
bindchange: function( e ) {
var that = this;
that.setdata( { currenttab: e.detail.current });
},
// 点击tab切换
swichnav: function( e ) {
var that = this;
if( this.data.currenttab === e.target.dataset.current ) {
return false;
}else{
that.setdata( {
currenttab: e.target.dataset.current
})
}
}
})
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
更多微信小程序 swiper制作tab切换实现。