GamepadHapticActuator: reset() 方法

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

GamepadHapticActuator 介面的 reset() 方法會停止硬體播放當前正在進行的振動效果。

語法

js
reset()

引數

無。

返回值

如果效果重置成功,則 Promise 解析為 "complete";如果效果被停止或被另一個效果替換,則 Promise 解析為 "preempted"

Promise 可能會因以下異常型別而拒絕:

InvalidStateError DOMException

如果當前文件未啟用或處於隱藏狀態,則 Promise 將因 InvalidStateError 而拒絕。

示例

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

setTimeout(() => {
  gamepad.vibrationActuator.reset();
}, 150);

gamepad.vibrationActuator
  .playEffect("dual-rumble", {
    startDelay: 0,
    duration: 200,
    weakMagnitude: 1.0,
    strongMagnitude: 1.0,
  })
  .then((result) => console.log(result));
// Should log "preempted" because reset() will run before the effect ends

規範

規範
Gamepad
# dom-gamepadhapticactuator-reset

瀏覽器相容性

另見