微信小程序自定义导航栏
1. 在需要的页面.json文件中配置使用自定义导航栏: “navigationStyle”: "custom"
2. app.js文件 计算导航栏高度等信息
App({
globalData: {},
onLaunch() {
let menuButtonObject = wx.getMenuButtonBoundingClientRect();
wx.getSystemInfo({
success: res => {
console.log('设备信息=', res, '状态栏的高度=', res.statusBarHeight)
let statusBarHeight = res.statusBarHeight,
navTop = menuButtonObject.top * 2,
navHeight = (statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight) * 2) * 2;
this.globalData.navHeight = navHeight;
this.globalData.navTop = navTop;
this.globalData.navLeft = (res.windowWidth - menuButtonObject.right) * 4
},
fail(err) {
console.log(err);
}
})
},
})
|