2019-01-03 15:37:24 500浏览
今天扣丁学堂HTML5培训老师给大家介绍一下关于微信小程序自定义导航栏实现源码详解,首先在微信小程序中导航栏是可以直接配置的,下面我们一起来看一下吧。
"window":{
"navigationStyle": "custom"
},
我就配置了这个属性,现在来看看我的界面
/**
* 当小程序初始化完成时,会触发 onLaunch(全局只触发一次)
*/
onLaunch: function () {
wx.getSystemInfo({
success: res => {
//导航高度
this.globalData.navHeight = res.statusBarHeight+46;
this.navH = res.statusBarHeight;
this.platform = res.platform;
}
})
},
this.globalData.navHeight这个变量是在app.js中定义的:
globalData: {
isPlayMusic :false,
doubanBase: "http://t.yushu.im",
navHeight:0
},
onLoad: function (options) {
this.setData({
navH: App.globalData.navHeight
})
},
var App = getApp();
data: {
navH:0
},
<view>
<view class='more_main' style='height:{{navH}}px'>
<view class='title_contanier'>
<text class="more_title">更多</text>
</view>
</view>
</view>
.more_title{
margin:0 auto;
margin-top: 75rpx;
text-align:center;
font-size: 32rpx;
}
.title_contanier{
display: flex;
flex-direction: row;
}
.more_main{
width: 100%;
background-color: greenyellow;
}
效果图:
【关注微信公众号获取更多学习资料】