某些设备在设备方向的变化alpha上不返回每个角度值。 代码如下:
window.addEventListener('deviceorientation', function(eventData) {
// gamma is the left-to-right tilt in degrees, where right is positive
var tiltLR = eventData.gamma;
var absolute = eventData.absolute;
document.getElementById("r4").innerHTML = absolute;
// beta is the front-to-back tilt in degrees, where front is positive
var tiltFB = eventData.beta;
// alpha is the compass direction the device is facing in degrees
var dir = eventData.alpha
// call our orientation event handler
deviceOrientationHandler(tiltLR, tiltFB, dir);
}, false);
eventData.absolute
返回undefined
的设备有alpha工作正常,但eventData.absolute
返回true
的设备有alpha不能正常工作(alpha返回{{1这只意味着不返回像0,180,360
等每个角度。是否可以通过任何Javascript代码修复此问题?