window.deviceorientation在Safari浏览器中不起作用

时间:2019-05-23 13:56:53

标签: javascript html mobile-safari device-orientation

我想使用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);
}

0 个答案:

没有答案