根据ui设计的需求,小程序的导航头部需要显示logo
需要显示的页面json文件设置
"usingComponents": {
"no-data":"../../components/no-data/no-data"
},
"navigationBarTitleText":"首页",
"enablePullDownRefresh": true ,
"navigationStyle":"custom"
}
.wxml 文件的设置
<view
style="z-index:22;border-bottom:2rpx solid rgba(0, 0, 0, 0.07);margin-bottom:38rpx;position:fixed;top:0;right:0;left:0;height:{{navHeight}}px;background:#fff;">
<image src="../../images/index/logo.png" mode="aspectFill" style="width:96rpx;height:80rpx;margin-top:{{navTop-4}}px;margin-left:32rpx"></image>
</view>
<view class="i_container" style="margin-top:{{navHeight}}px">
....content
</view>
在.js动态获取dom的位置,获取导航条可以设置的宽高
onReady: function () {
let menuButtonObject = wx.getMenuButtonBoundingClientRect();
console.log(menuButtonObject,' "navigationStyle":"custom",')
wx.getSystemInfo({
success: res => {
console.log(res)
let statusBarHeight = res.statusBarHeight,
navTop = menuButtonObject.top,
navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight) * 2;
this.setData({
navTop:navTop,
navHeight:navHeight,
},()=>{
console.log(this.data.navHeight,this.data.navTop)
})
},
})
},
|