--- title: deviceorientation slug: Web/API/Window/deviceorientation_event tags: - Имитация смены положения - Определение ориентации - Ориентация - Сенсоры translation_of: Web/API/Window/deviceorientation_event ---
Событие deviceorientation
срабатывает, когда с сенсоров ориентации поступают новые данные о текущем положении устройства внутри Земной системы координат. Эти данные собираются с помощью магнитометра устройства. Более детальное объяснение дано в Ориентация и объяснение данных движения.
window
)Property | Type | Description |
---|---|---|
target {{readonlyInline}} |
{{domxref("EventTarget")}} | The event target (the topmost target in the DOM tree). |
type {{readonlyInline}} |
{{domxref("DOMString")}} | The type of event. |
bubbles {{readonlyInline}} |
{{jsxref("Boolean")}} | Whether the event normally bubbles or not |
cancelable {{readonlyInline}} |
{{jsxref("Boolean")}} | Whether the event is cancellable or not? |
alpha {{readonlyInline}} |
double (float) | The current orientation of the device around the Z axis; that is, how far the device is rotated around a line perpendicular to the device. |
beta {{readonlyInline}} |
double (float) | The current orientation of the device around the X axis; that is, how far the device is tipped forward or backward. |
gamma {{readonlyInline}} |
double (float) | The current orientation of the device around the Y axis; that is, how far the device is turned left or right. |
absolute {{readonlyInline}} |
{{jsxref("boolean")}} | This value is true if the orientation is provided as a difference between the device coordinate frame and the Earth coordinate frame; if the device can't detect the Earth coordinate frame, this value is false . |
if (window.DeviceOrientationEvent) { window.addEventListener("deviceorientation", function(event) { // alpha: rotation around z-axis var rotateDegrees = event.alpha; // gamma: left to right var leftToRight = event.gamma; // beta: front back motion var frontToBack = event.beta; handleOrientationEvent(frontToBack, leftToRight, rotateDegrees); }, true); } var handleOrientationEvent = function(frontToBack, leftToRight, rotateDegrees) { // Сделайте что-нибудь необычное здесь };
{{Compat("api.Window.deviceorientation_event")}}