Home > WeChat Applet > Mini Program Development > Sample code for top navigation bar in mini program

Sample code for top navigation bar in mini program

巴扎黑
Release: 2017-09-12 10:56:29
Original
2394 people have browsed it

微信小程序 开发之顶部导航栏

需求:顶部导航栏

wxml:

<!--导航条--> 
<view class="navbar"> 
 <text wx:for="pw_navbar" data-idx="pw_index" class="item pw_currentTab==index ? 'active' : ''" wx:key="unique" bindtap="navbarTap">pw_item</text> 
</view> 
 
<!--首页--> 
<view hidden="pw_currentTab!==0"> 
 tab_01 
</view> 
 
<!--搜索--> 
<view hidden="pw_currentTab!==1"> 
 tab_02 
</view> 
 
<!--我--> 
<view hidden="pw_currentTab!==2"> 
 tab_03 
</view>
Copy after login

wxss:

page{ 
 display: flex; 
 flex-direction: column; 
 height: 100%; 
} 
.navbar{ 
 flex: none; 
 display: flex; 
 background: #fff; 
} 
.navbar .item{ 
 position: relative; 
 flex: auto; 
 text-align: center; 
 line-height: 80rpx; 
} 
.navbar .item.active{ 
 color: #FFCC00; 
} 
.navbar .item.active:after{ 
 content: ""; 
 display: block; 
 position: absolute; 
 bottom: 0; 
 left: 0; 
 right: 0; 
 height: 4rpx; 
 background: #FFCC00; 
}
Copy after login

js:

var app = getApp() 
Page({ 
 data: { 
  navbar: ['首页', '搜索', '我'], 
  currentTab: 0 
 }, 
 navbarTap: function(e){ 
  this.setData({ 
   currentTab: e.currentTarget.dataset.idx 
  }) 
 } 
})
Copy after login

The above is the detailed content of Sample code for top navigation bar in mini program. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template