Constructor
Create a new WebHaptics instance.Methods
trigger()
Trigger a haptic vibration pattern.The haptic pattern to trigger. Can be:
number- Single vibration duration in millisecondsstring- Preset name (e.g.,"success","error")number[]- Array of alternating on/off durationsVibration[]- Array of vibration objects with duration, intensity, and delayHapticPreset- Preset object with a pattern array
Optional trigger configuration
Default intensity for vibrations (0-1). Individual vibrations can override this.
Returns a promise that resolves when the haptic pattern completes
Examples
cancel()
Cancel any currently running haptic pattern.destroy()
Clean up the WebHaptics instance and remove all DOM elements.- Cancels any active haptic patterns
- Removes the haptic switch UI element
- Closes the audio context (if debug mode was enabled)
- Cleans up all internal resources
setDebug()
Enable or disable debug mode.Whether to enable debug mode
- Audio feedback for haptic events
- Visual indicators
- Console logging
setShowSwitch()
Show or hide the haptic feedback toggle switch.Whether to show the toggle switch
Static Properties
isSupported
Check if haptic feedback is supported in the current environment.true if navigator.vibrate() is available, false otherwiseType Definitions
See Types for complete type definitions includingWebHapticsOptions, HapticInput, TriggerOptions, and Vibration.