我正在尝试使用device-orientation,移动设备来检测JavaScript。
我看了文档,看了其他的StackOverflow问题,看了关于这个主题的视频,这看起来非常简单,但我就是不能让它开始工作…。
这是我目前的代码:
function handleOrientation(event) {
var absolute = event.absolute;
var alpha = event.alpha;
var beta = event.beta;
var gamma = event.gamma;
document.querySelector(".deviceAbsolute").innerHTML = absolute;
document.querySelector(".deviceAlpha").innerHTML = alpha;
document.querySelector(".deviceBeta").innerHTML = beta;
document.querySelector(".deviceGamma").innerHTML = gamma;
}
window.addEventListener("deviceorientation", handleOrientation, true);<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Build 7</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
deviceAbsolute = <span class="deviceAbsolute">no input</span><br>
deviceAlpha = <span class="deviceAlpha">no input</span><br>
deviceBeta = <span class="deviceBeta">no input</span><br>
deviceGamma = <span class="deviceGamma">no input</span>
</body>
</html>
我将这段代码上传到我的but空间,并使用iPhone和iPad进行了测试,但什么也没有发生。
编辑:
我终于找到了一个实用的演示:https://sensor-js.xyz/demo.html --它在我的iPad和iPad上运行,在Safari上运行。-现在的问题是:他们是怎么做到的?
发布于 2021-01-14 08:00:03
看看这个:https://developer.mozilla.org/en-US/docs/Web/API/Gyroscope#example
let gyroscope = new Gyroscope({frequency: 60});
gyroscope.addEventListener('reading', e => {
console.log("Angular velocity along the X-axis " + gyroscope.x);
console.log("Angular velocity along the Y-axis " + gyroscope.y);
console.log("Angular velocity along the Z-axis " + gyroscope.z);
});
gyroscope.start();https://stackoverflow.com/questions/65715239
复制相似问题