DevicePosture: sự kiện change
Khả dụng hạn chế
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Sự kiện change của giao diện DevicePosture được kích hoạt khi tư thế của thiết bị thay đổi, ví dụ khi một thiết bị có thể gập từ tư thế folded sang tư thế continuous.
Cú pháp
Sử dụng tên sự kiện trong các phương thức như addEventListener(), hoặc đặt thuộc tính xử lý sự kiện.
js
addEventListener("change", (event) => { })
onchange = (event) => { }
Loại sự kiện
Một Event tổng quát.
Ví dụ
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);
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| Device Posture API> # dom-deviceposture-onchange> |
Tương thích trình duyệt
Xem thêm
- CSS
device-posture@mediafeature - Device Posture API
- Origin trial for Foldable APIs on developer.chrome.com (2024)