0
点赞
收藏
分享

微信扫一扫

小程序头部高度获取

小程序头部高度获取_状态栏高度

export function getNavigationBarHeight() {
  // 获取系统信息
  const systemInfo = getItem(GLOBAL_SYSTEM_INFO);
  //获取胶囊信息
  const menuBtnInfo = uni.getMenuButtonBoundingClientRect()
  
  //状态栏高度
  const statusBarHeight = systemInfo.statusBarHeight
  
   //胶囊高度
  const menuHeight = menuBtnInfo.height
  
   //胶囊与顶部的距离
  const menuTop = menuBtnInfo.top
  
  //导航栏高度= (胶囊顶部距离-状态栏高度) x 2 + 胶囊的高度
  const navigatorHeight = (menuTop - statusBarHeight) * 2 + menuHeight
  
  //总高度 = 状态栏的高度 + 导航栏高度
  return (statusBarHeight + navigatorHeight) * 2
}

onLaunch: function () {    
    var that = this;
    //获取设备信息
    let systemInfo = wx.getSystemInfoSync()
    that.globalData.systemInfo = systemInfo
    //1rpx 像素值 
    let pixelRatio1 = 750 / systemInfo.windowWidth;
    that.globalData.pixelRatio1 = pixelRatio1
    //胶囊信息
    let menu = wx.getMenuButtonBoundingClientRect()
    that.globalData.menuInfo = menu
    //状态栏高度
    let statusHeight = systemInfo.statusBarHeight
    that.globalData.statusHeight = statusHeight * pixelRatio1
    //导航栏高度
    let naviHeight = (menu.top - statusHeight) * 2 + menu.height
    that.globalData.naviHeight = naviHeight * pixelRatio1
    //顶部高度 = 状态栏高度 + 导航栏高度
    that.globalData.topHeight = (statusHeight + naviHeight) * pixelRatio1
    //屏幕高度
    let screenHeight = systemInfo.screenHeight
    that.globalData.screenHeight = screenHeight * pixelRatio1
    //底部高度 = 屏幕高度 - 安全区域bottom
    let bottom = systemInfo.safeArea.bottom
    that.globalData.bottomHeight = (screenHeight - bottom) * pixelRatio1
    }

举报

相关推荐

0 条评论