值
一个字符串,表示设备的当前姿态。该值可以是以下之一:
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 |
浏览器兼容性
加载中…
另见
- CSS
device-posture@media特性 - 设备姿态 API
- developer.chrome.com 上的折叠 API 来源试用 (2024)