Gyroscope:Gyroscope() 构造函数

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

Gyroscope() 构造函数创建一个新的 Gyroscope 对象,它在每次读取时提供设备沿所有三个轴的角速度。

语法

js
new Gyroscope()
new Gyroscope(options)

参数

options 可选

选项如下:

frequency 可选

每秒采样所需的次数,即每秒调用 reading 事件的次数。可使用整数或者小数,小数用于小于一秒的频率。实际读取频率取决于设备硬件,因此可能小于所请求的。

referenceFrame 可选

'device''screen',默认值是 'device'

异常

SecurityError DOMException

此特性的使用被权限策略阻止。

规范

Specification
Gyroscope
# dom-gyroscope-gyroscope

浏览器兼容性

BCD tables only load in the browser

参见