使用的场景:不需要节点写死高度,节点到tabBar的距离自适应
data:{
listHeight: 0, // 节点到tabBar的距离
}
getRect () {
const _this = this //保存this
wx.createSelectorQuery().select('#goodsList').boundingClientRect(function(rect){
const nodeTop = rect.top; // 节点的上边界坐标
const {windowHeight} = wx.getWindowInfo(); //可使用窗口高度,单位px
_this.setData({
listHeight: windowHeight-nodeTop // 节点到tabBar的距离
})
}).exec()
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.getRect()
},
getWindowInfo需要小程序基础库版本不低于 2.21.3,可使用getSystemInfoSync
功能描述
1. windowHeight 概念
可使用窗口高度,即:屏幕高度(screenHeight) - 导航(tabbar)高度 - 导航栏高度 - 状态栏高度。
在不含导航(tabbar)的页面
windowHeight =屏幕高度(screenHeight) - 导航栏高度 - 状态栏高度
注意:单位是px