计算公式如下
let systemInfo = wx.getSystemInfoSync();
const height= systemInfo.screenHeight – systemInfo.safeArea.bottom + 50
这里我来计算中间空白的高度,就需要从搜索框以及底部tabbar中减去。样例代码如下
// 获取顶部搜索框的高度
topQuery.select(".search").boundingClientRect((rect)=>{
console.log("顶部搜索栏:"+rect.height)
if(rect){
let systemInfo = wx.getSystemInfoSync();
const height= systemInfo.screenHeight - systemInfo.safeArea.bottom + 50
console.log("顶部高度:"+rect.height+" 底部tabbar:"+height)
that.setData({
height : systemInfo.windowHeight - rect.height - height
})
}
}).exec()
关于为什么+50
在控制台的wmxl中查看每天tabbar的item高度,发现就是50