Movatterモバイル変換


[0]ホーム

URL:


  1. Веб-технологии для разработчиков
  2. Интерфейсы веб API
  3. Window
  4. deviceorientation

This page was translated from English by the community.Learn more and join the MDN Web Docs community.

View in EnglishAlways switch to English

deviceorientation

Baseline 2023
Newly available

Since September 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Событиеdeviceorientation срабатывает, когда с сенсоров ориентации поступают новые данные о текущем положении устройства внутри Земной системы координат. Эти данные собираются с помощью магнитометра устройства. Более детальное объяснение дано вОриентация и объяснение данных движения.

Общая информация

Спецификация

СобытиеDeviceOrientation

Определение

DeviceOrientationEvent

Всплывает

Нет

Отменяемо

Нет

Целевой элемент

По умолчанию (window)

Действие по умолчанию

Нет

Свойства

PropertyTypeDescription
targetТолько для чтенияEventTargetThe event target (the topmost target in the DOM tree).
typeТолько для чтенияDOMStringThe type of event.
bubblesТолько для чтенияBooleanWhether the event normally bubbles or not
cancelableТолько для чтенияBooleanWhether the event is cancellable or not?
alphaТолько для чтения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Только для чтенияdouble (float)The current orientation of the device around the X axis; that is, how far the device is tipped forward or backward.
gammaТолько для чтенияdouble (float)The current orientation of the device around the Y axis; that is, how far the device is turned left or right.
absoluteТолько для чтенияbooleanThis value istrue 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 isfalse.

Пример

js
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,) {  // Сделайте что-нибудь необычное здесь};

Совместимость с браузерами

Похожие события

Смотрите также

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp