值
一個字串,表示裝置的當前姿態。該值可以是以下之一:
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)