uniapp 獲取状态栏 + 胶囊高度

  // 计算状态栏高度
            getMenuButton() {
                // 状态栏高度
                let ztl = uni.getSystemInfoSync().statusBarHeight;
                // 获取微信胶囊的位置信息
                const custom = wx.getMenuButtonBoundingClientRect()
                // 导航栏高度(标题栏高度) = 胶囊高度 + (顶部距离 - 状态栏高度) * 2
                let ztlh2 = custom.height + (custom.top - ztl) * 2
                // 总体高度 = 状态栏高度 + 导航栏高度
                getApp().globalData.topHeight = ztl + ztlh2
                console.log(getApp().globalData.topHeight);
            }
View Code

 

posted @ 2022-10-15 16:36  咸瑜  阅读(269)  评论(0编辑  收藏  举报