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

瀏覽器相容性

另見