DevicePosture: type 属性

可用性有限

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

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

DevicePosture 接口的 type 只读属性返回设备的当前姿态。

一个字符串,表示设备的当前姿态。该值可以是以下之一:

continuous

表示屏幕处于平坦姿态——这可以包括折叠设备在平放使用时、无缝曲面显示器,或者标准的台式机、笔记本电脑、平板电脑或手机屏幕。

folded

表示屏幕处于折叠姿态——这可以包括折叠设备以书本或笔记本电脑姿态使用时。

示例

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

浏览器兼容性

另见