Navigator:devicePosture 属性

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

实验性: 这是一项实验性技术
在生产中使用此技术之前,请仔细检查浏览器兼容性表格

Navigator.devicePosture 只读属性返回浏览器的 DevicePosture 对象,该对象允许开发者查询设备的当前姿态(即视口是否处于展开或折叠状态)并响应姿态变化来运行代码。

一个 DevicePosture 对象。

示例

js
const postureOutput = document.getElementById("currentPosture");

function reportPostureOutput() {
  // type property returns "continuous" or "folded"
  postureOutput.textContent = `Device posture: ${navigator.devicePosture.type}`;
}

navigator.devicePosture.addEventListener("change", reportPostureOutput);

规范

规范
设备姿态 API
# dom-navigator-deviceposture

浏览器兼容性

另见