Window: devicemotion event

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.

L'évènement devicemotion est déclenché à intervalles réguliers et indique la quantité de force physique d'accélération que le périphérique reçoit à ce moment. Il fournit également des informations sur le taux de rotation, si disponible.

Bouillonne Non
Annulable Non
Interface DeviceMotionEvent
Propriété gestionnaire d'évènement Window.ondevicemotion

Exemples

js
function handleMotionEvent(event) {
  var x = event.accelerationIncludingGravity.x;
  var y = event.accelerationIncludingGravity.y;
  var z = event.accelerationIncludingGravity.z;

  // Faire quelque chose de génial.
}

window.addEventListener("devicemotion", handleMotionEvent, true);

Spécifications

Specification
Device Orientation and Motion
# devicemotion
Device Orientation and Motion
# ref-for-dom-window-ondevicemotion

Compatibilité des navigateurs

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
devicemotion event

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Voir aussi