首頁  >  文章  >  微信小程式  >  微信小程式如何實現頂部普通選項卡非swiper效果的實例

微信小程式如何實現頂部普通選項卡非swiper效果的實例

黄舟
黄舟原創
2017-09-12 09:24:132372瀏覽

這篇文章主要為大家詳細介紹了微信小程式實現頂部普通選項卡效果,非swiper,具有一定的參考價值,感興趣的小伙伴們可以參考一下

背景:前段時間寫了一個搶紅包小程序,裡面涉及到了頂部選項卡,把它抽了出來。

效果圖:

#下面直接上程式碼:

wxml:


<view class="navbar"> 
 <text wx:for="{{navbar}}" data-index="{{index}}" 
 class="item {{currentIndex==index?&#39;active&#39;:&#39;&#39;}}" 
 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效果的實例的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn