ScreenOrientation: sự kiện change
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2023.
Sự kiện change của giao diện ScreenOrientation được kích hoạt khi hướng của màn hình thay đổi, ví dụ khi người dùng xoay điện thoại di động của họ.
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 trình xử lý sự kiện.
js
addEventListener("change", (event) => { })
onchange = (event) => { }
Loại sự kiện
Một Event chung.
Ví dụ
Trong ví dụ sau, callback change in ra screen orientation type và angle mới.
js
screen.orientation.addEventListener("change", (event) => {
const type = event.target.type;
const angle = event.target.angle;
console.log(`ScreenOrientation change: ${type}, ${angle} degrees.`);
});
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| Screen Orientation> # dom-screenorientation-onchange> |