DevicePosture

可用性有限

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

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

DevicePosture 接口是 Device Posture API 的一部分,它代表设备的状态,即视口是处于平坦还是折叠状态。

EventTarget DevicePosture

实例属性

继承其父级 EventTarget 的属性。

type 只读 实验性

返回设备的当前状态。

事件

change 实验性

当设备状态发生变化时触发。

示例

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-deviceposture

浏览器兼容性

另见