Gyroscope:x 属性

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

安全上下文: 此功能仅在安全上下文(HTTPS)中可用,且支持此功能的浏览器数量有限。

Gyroscope 接口的 x 只读属性返回一个数字,该数字指定了设备沿其 x 轴的角速度。

一个 Number

示例

陀螺仪通常在 reading 事件回调中读取。在下面的示例中,这每秒发生六十次。

js
let gyroscope = new Gyroscope({ frequency: 60 });

gyroscope.addEventListener("reading", (e) => {
  console.log(`Angular velocity along the X-axis ${gyroscope.x}`);
  console.log(`Angular velocity along the Y-axis ${gyroscope.y}`);
  console.log(`Angular velocity along the Z-axis ${gyroscope.z}`);
});
gyroscope.start();

规范

规范
Gyroscope
# gyroscope-x

浏览器兼容性