DeviceMotionEvent API All In One
设备
运动
事件 / 设备动作
事件
https://caniuse.com/?search=DeviceMotionEvent
Warning: Currently, Firefox and Chrome do not handle the coordinates the same way.
Take care about this while using them.
警告:目前,Firefox 和 Chrome 处理坐标的方式不同。
使用它们时请注意这一点。
https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent
new DeviceMotionEvent(type)
new DeviceMotionEvent(type, options)
https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent
https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEventAcceleration
https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEventRotationRate
devicemotion
window.addEventListener('devicemotion', (event) => {
console.log(`event =`, event);
});
window.ondevicemotion = (event) => {
// console.log(`event =`, event);
};
function handleMotionEvent(event) {
// 重力加速度
const x = event.accelerationIncludingGravity.x;
const y = event.accelerationIncludingGravity.y;
const z = event.accelerationIncludingGravity.z;
// Do something awesome.
}
window.addEventListener("devicemotion", handleMotionEvent, true);
https://developer.mozilla.org/en-US/docs/Web/API/Window/devicemotion_event
DeviceOrientation Event Specification
Editor’s Draft, 30 January 2023
https://w3c.github.io/deviceorientation/#devicemotion