uniapp 获取最底部高度
时间: 2023-09-03 21:09:29 浏览: 54
可以使用uni.getSystemInfoSync()获取系统信息,再通过uni.createSelectorQuery()获取页面节点信息,最后计算出最底部的高度。
示例代码:
```
// 获取系统信息
const systemInfo = uni.getSystemInfoSync()
// 创建选择器
const query = uni.createSelectorQuery()
// 获取页面节点信息
query.select('.page').boundingClientRect()
// 计算最底部的高度
query.exec((res) => {
const pageHeight = res[0].height
const bottomHeight = systemInfo.windowHeight - res[0].bottom
console.log(`最底部高度为:${bottomHeight}`)
})
```
相关问题
uniapp获取底部tabbar高度
你可以通过uni.getSystemInfoSync()获取系统信息,从而得到底部tabbar的高度。具体代码可以参考以下示例:
```
var systemInfo = uni.getSystemInfoSync();
var tabBarHeight = systemInfo.screenHeight - systemInfo.windowHeight - systemInfo.statusBarHeight - 50; // 50为底部tabbar默认高度
console.log('底部tabbar的高度为:' + tabBarHeight);
```
uniapp获取屏幕底部安全区域高度
在uniapp中,可以通过以下代码获取屏幕底部安全区域的高度:
```javascript
uni.getSystemInfo({
success: function (res) {
let screenHeight = res.screenHeight;
let windowHeight = res.windowHeight;
let bottomBarHeight = screenHeight - windowHeight;
console.log('底部安全区域高度:' + bottomBarHeight + 'px');
}
});
```
其中,`screenHeight`表示屏幕的高度,`windowHeight`表示可使用窗口的高度,`bottomBarHeight`表示底部安全区域的高度。