GamepadHapticActuator

Limited availability

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

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

Gamepad APIGamepadHapticActuator 接口表示控制器中设计向用户提供触觉反馈的硬件(如果可用),最常见的是振动硬件。

此接口可通过 Gamepad.hapticActuators 属性访问。

实例属性

GamepadHapticActuator.type 只读

返回表示触觉硬件类型的枚举值。

实例方法

GamepadHapticActuator.pulse() 只读

使硬件在指定的期间内脉冲达到一定强度。

GamepadHapticActuator.playEffect() 只读

使硬件播放特定的振动模式。

示例

js
const gamepad = navigator.getGamepads()[0];

gamepad.hapticActuators[0].pulse(1.0, 200);

gamepad.vibrationActuator.playEffect("dual-rumble", {
  startDelay: 0,
  duration: 200,
  weakMagnitude: 1.0,
  strongMagnitude: 1.0,
});

规范

Specification
Gamepad
# gamepadhapticactuator-interface

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
GamepadHapticActuator
canPlayEffectType
DeprecatedNon-standard
effects
Experimental
trigger-rumble effect type
Experimental
playEffect
params.leftTrigger parameter
Experimental
params.rightTrigger parameter
Experimental
trigger-rumble effect type
Experimental
pulse
reset
Secure context required
type
DeprecatedNon-standard

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
Non-standard. Check cross-browser support before using.
Deprecated. Not for use in new websites.
User must explicitly enable this feature.

参见