Javascript 移动加速计和陀螺仪检查功能
我正在寻找一种合适的方法来检查移动设备(主要是android和iphone)上是否有javascript格式的加速计和陀螺仪 也许通过尝试确定调用的函数是否返回了某些内容?您可以尝试以下方法:Javascript 移动加速计和陀螺仪检查功能,javascript,android,iphone,Javascript,Android,Iphone,我正在寻找一种合适的方法来检查移动设备(主要是android和iphone)上是否有javascript格式的加速计和陀螺仪 也许通过尝试确定调用的函数是否返回了某些内容?您可以尝试以下方法: if (window.DeviceMotionEvent) { window.addEventListener('devicemotion', deviceMotionHandler, false); } else { // This device doesn't support accelera
if (window.DeviceMotionEvent) {
window.addEventListener('devicemotion', deviceMotionHandler, false);
} else {
// This device doesn't support accelerators
}
function deviceMotionHandler(e) {
var acceleration = e.accelerationIncludingGravity;
var accelerationX = acceleration.x;
var accelerationYe.acceleration.y;
var accelerationZ = acceleration.z;
if (e.rotationRate) {
var rotation = e.rotationRate;
var rotationAlpha = rotation.alpha;
var rotationBeta = rotation.beta;
var rotationGamma = rotation.gamma;
}
}
这篇文章将进一步阐明这个问题。您可以尝试以下方法:
if (window.DeviceMotionEvent) {
window.addEventListener('devicemotion', deviceMotionHandler, false);
} else {
// This device doesn't support accelerators
}
function deviceMotionHandler(e) {
var acceleration = e.accelerationIncludingGravity;
var accelerationX = acceleration.x;
var accelerationYe.acceleration.y;
var accelerationZ = acceleration.z;
if (e.rotationRate) {
var rotation = e.rotationRate;
var rotationAlpha = rotation.alpha;
var rotationBeta = rotation.beta;
var rotationGamma = rotation.gamma;
}
}
这篇文章将进一步阐明这个问题