微信小程序实现顶部普通选项卡效果(非swiper)
背景:前段时间写了一个抢红包小程序,里面涉及到了顶部选项卡,把它抽了出来。
效果图:

下面直接上代码:
wxml:
<view class="navbar">
<text wx:for="{{navbar}}" data-index="{{index}}"
class="item {{currentIndex==index?'active':''}}"
bindtap="navbarTab" wx:key="unique">{{item}}</text>
</view>
<view hidden="{{currentIndex!==0}}">
</view>
<view hidden="{{currentIndex!==1}}">
</view>wxss:
.navbar{
display: flex;
width: 100%;
flex-direction: row;
line-height: 80rpx;
position: fixed;
top: 0;
}
.navbar .item{
flex: auto;
font-size: 30rpx;
text-align: center;
background: #fff;
font-weight: bold;
}
.navbar .item.active{
color: #36DB2C;
position: relative;
}
.navbar .item.active::after{
content: "";
display: block;
position: absolute;
height: 4rpx;
bottom: 0;
left: 0;
right: 0;
background: #36DB2C;
}js:
data: {
navbar: ["我发出的", "我收到的"],
currentIndex: 0,//tabbar索引
},
navbarTab: function (e) {
this.setData({
currentIndex: e.currentTarget.dataset.index
});
},以上是实现过程基本代码,省去了中间内容的代码。顶部个数是循环出来的,可以根据自己的实际需求设置。
附:swiper顶部选项卡链接
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持安科网。
相关推荐
APCDE 2020-06-11
viewerlin 2020-05-25
adc00 2020-01-04
老高 2019-12-30
luoj 2011-09-13
xiaoguolaoshi 2008-07-20
Rgenxiao 2011-09-08
支离破碎 2014-06-30
qiuhaotc 2012-02-19
85931235 2012-03-28
bruceli 2019-05-14
南城小伙 2019-06-10
逆风飞舞0 2019-05-14
87530399 2014-05-26
chenyangah 2017-03-31
84236532 2016-11-17
zhangpuego 2016-07-16
Jiminull 2016-03-03