DevicePosture: change 事件
當裝置的姿態發生變化時,DevicePosture 介面的 change 事件就會觸發。例如,當一個可摺疊裝置從 folded 姿態變為 continuous 姿態時。
語法
在諸如 addEventListener() 之類的方法中使用事件名稱,或設定事件處理程式屬性。
js
addEventListener("change", (event) => { })
onchange = (event) => { }
事件型別
一個通用的 Event。
示例
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-onchange |
瀏覽器相容性
載入中…
另見
- CSS
device-posture@media特性 - 裝置姿態 API
- developer.chrome.com 上的摺疊 API 來源試用 (2024)