有关设备方向的事件侦听器停止工作

时间:2019-04-24 17:33:45

标签: javascript mobile event-listener device-orientation

我有一个简单的脚本,可读取设备的x y z方向。我在许多应用程序中都使用了它,但是它停止了工作。在控制台中没有错误,不知道为什么。有人知道吗?似乎该事件不再被调用了。

const accigElem = document.getElementById('accig');
const accElem = document.getElementById('acc');
const rotElem = document.getElementById('rot');
const oriElem = document.getElementById('ori');

function onDeviceMotion(evt) {
  const interval = evt.interval;
  let e, str;

  e = evt.accelerationIncludingGravity;
  str = "x: " + e.x + "<br>";
  str += "y : " + e.y + "<br>";
  str += "z: " + e.z + "<br>";
  str += "interval: " + interval;
  accigElem.innerHTML = str;


}




window.addEventListener('devicemotion', onDeviceMotion);

0 个答案:

没有答案