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

瀏覽器相容性

另見