我想使用JavaScript为手机触发设备定位事件, 我的代码在chrome中工作正常,但在safari中不起作用
if (window.DeviceOrientationEvent) {
window.addEventListener('deviceorientation', eventData => {
// gamma: Tilting the device from left to right. Tilting the device to the right will result in a positive value.
const tiltLR = eventData.gamma;
// beta: Tilting the device from the front to the back. Tilting the device to the front will result in a positive value.
const tiltFB = eventData.beta;
// alpha: The direction the compass of the device aims to in degrees.
const dir = eventData.alpha;
// Call the function to use the data on the page.
deviceOrientationHandler(tiltLR, tiltFB, dir);
}, false);
}