DeviceMotionEvent API All In One
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
demos
https://codepen.io/xgqfrms/pen/oNPemaP?editors=1010
refs
H5 实现
摇一摇
HTML5 提供的 DOM事件来获得设备物理方向及运动的信息,包括:陀螺仪
、罗盘
及加速计
。
deviceorientation,其提供设备的物理方向信息,表示为一系列本地坐标系的旋角。
devicemotion,其提供设备的加速信息,表示为定义在设备上的坐标系
中的迪卡尔坐标。其还提供了设备在坐标系中的自转速率。
compassneedscalibration,其用于使用罗盘信息校准上述事件。
http://leooman.com/src/web/devicemotion.html
©xgqfrms 2012-2025
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17188524.html
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2022-03-07 js WeakMap All In One
2022-03-07 how to change your GitHub first commit history timestamp All In One
2022-03-07 js try...finally All In One
2022-03-07 Vuex 4.x All In One
2022-03-07 vitepress & vuepress All In One
2022-03-07 PRPL 模式 All in One
2022-03-07 前端代码构建工具 All In One