在uniapp中,有哪些内置的手机高度变量?
- User
在uniapp中,有哪些内置的手机高度变量?
- Assistant
在 uni-app 中,您可以通过以下方式获取与手机高度相关的内置变量:
-
CSS 内置变量:
-
--status-bar-height:表示系统状态栏的高度。在微信小程序环境中固定为 25px,在 App 中为手机实际状态栏高度。 -
--window-top:内容区域距离顶部的距离。在 App 中为 0,在小程序中为 NavigationBar 的高度。 -
--window-bottom:内容区域距离底部的距离。在 App 中为 0,在小程序中为 TabBar 的高度。
这些变量可用于 CSS 中,确保在不同平台上布局的一致性。
-
-
系统信息 API:
您可以使用
uni.getSystemInfo或uni.getSystemInfoSync方法获取设备的系统信息,其中包含屏幕高度等参数。-
screenHeight:屏幕高度。 -
windowHeight:可使用窗口的高度,不包含导航栏和 TabBar 的高度。 -
statusBarHeight:状态栏的高度。
示例代码:
uni.getSystemInfo({ success: function (res) { console.log('屏幕高度:', res.screenHeight); console.log('可使用窗口高度:', res.windowHeight); console.log('状态栏高度:', res.statusBarHeight); } }); -
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.