149条记录

小程序获取头部标题和刘海的高度

在 app.js 中加入

winsub:function(){
    wx.getSystemInfo({
      //1.获取机器信息
      //2.计算标题栏高度(screenHeight-windowHeight)
      //3.iphone:64,iphneX:88,acdroid:68 
      success:(res)=>{
        this.globalData.platform=res.platform;
        let totalTopHeight=68;
        if (res.model.indexOf('iPhone X') !== -1){
          totalTopHeight=88;
        }else if(res.model.indexOf('iPhone')!==-1){
          totalTopHeight=64;
        }
        this.wininfo.barh = res.statusBarHeight;
        this.wininfo.tith = totalTopHeight - res.statusBarHeight;
      },
      fail(){
        this.wininfo.barh=0;
        this.wininfo.tith=0;
      }
    })
  }
  ,
  wininfo:{
    barh:0,
    tith:0
  },

使用方法

data:{
    barheightapp.wininfo.barh + 10
}