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

瀏覽器相容性

另見