Window : l'événement deviceorientation
Baseline 2023Newly 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 deviceorientation
est déclenché lorsque des données sont disponibles, à partir d'un capteur d'orientation, sur l'orientation actuelle de l'appareil par rapport au cadre de coordonnées de la Terre. Ces données sont recueillies à partir d'un magnétomètre à l'intérieur de l'appareil. Voir Données d'orientation et de mouvement expliquées pour plus de détails.
Propagation | Non |
---|---|
Annulable | Non |
Interface |
DeviceOrientationEvent
|
Propriété du gestionnaire d'événements |
window.ondeviceorientation
|
Exemple
if (window.DeviceOrientationEvent) {
window.addEventListener(
"deviceorientation",
function (event) {
// alpha : rotation autour de l'axe z
var rotateDegrees = event.alpha;
// gamma : de gauche à droite
var leftToRight = event.gamma;
// bêta : mouvement avant-arrière
var frontToBack = event.beta;
handleOrientationEvent(frontToBack, leftToRight, rotateDegrees);
},
true,
);
}
var handleOrientationEvent = function (
frontToBack,
leftToRight,
rotateDegrees,
) {
// faire quelque chose d'étonnant
};
Spécifications
Specification |
---|
Device Orientation and Motion # deviceorientation |
Device Orientation and Motion # ref-for-dom-window-ondeviceorientation |
Compatibilité des navigateurs
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
deviceorientation event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Uses a non-standard name.
- Has more compatibility info.
Voir aussi
- L'événement
devicemotion
- Détection de l'orientation des appareils.
- Explication des données d'orientation et de mouvement
- Simulation d'événements d'orientation sur les navigateurs de bureau avec orientation-devtool.