GamepadButton:touched 属性

可用性有限

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

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

GamepadButton 接口的 touched 属性返回一个布尔值,表示一个能够检测触摸的按钮当前是否被触摸(true)或未被触摸(false)。

如果该按钮无法检测触摸但能返回一个模拟值,则当该值大于 0 时,此属性为 true,否则为 false。如果该按钮既不能检测触摸也只能报告一个数字值,则它应镜像 GamepadButton.pressed 属性。

一个布尔值。如果被触摸,则为 true。

示例

js
let gp = navigator.getGamepads()[0]; // Get the first gamepad object

if (gp.buttons[0].touched) {
  // respond to button being touched
}

规范

规范
Gamepad
# dom-gamepadbutton-touched

浏览器兼容性

另见