小程序的自定义头,左上角显示图标

根据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>
// 当变成自定义的头导航后,不再占用高度,具体的内容盒子需要设置margin-top预留自定义的导航条的高度
<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)
          })
      },
    })
  },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值