Navigator: vibrate() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Thevibrate() method of theNavigator interface pulses the vibrationhardware on the device, if such hardware exists. If the device doesn't supportvibration, this method has no effect. If a vibration pattern is already in progress whenthis method is called, the previous pattern is halted and the new one begins instead.
If the method was unable to vibrate because of invalid parameters, it will returnfalse, else it returnstrue. If the pattern leads to a toolong vibration, it is truncated: the max length depends on the implementation.
Some devices may not vibrate if they are in Silent mode or Do Not Disturb (DND) mode. To ensure vibration works, make sure these modes are turned off and that vibration is enabled in the system settings.
In this article
Syntax
vibrate(pattern)Parameters
patternProvides a pattern of vibration and pause intervals. Each value indicates a numberof milliseconds to vibrate or pause, in alternation. You may provide either a singlevalue (to vibrate once for that many milliseconds) or an array of values toalternately vibrate, pause, then vibrate again. SeeVibration API for details.
Passing a value of0, an empty array, or an array containing all zeroswill cancel any currently ongoing vibration pattern.
Return value
A boolean.
Security
Sticky user activation is required. The user has to interact with the page or a UI element in order for this feature to work.
Examples
navigator.vibrate(200); // vibrate for 200msnavigator.vibrate([ 100, 30, 100, 30, 100, 30, 200, 30, 200, 30, 200, 30, 100, 30, 100, 30, 100,]); // Vibrate 'SOS' in Morse.Specifications
| Specification |
|---|
| Vibration API> # dom-navigator-vibrate> |