Vibration API
suggest changeModern mobile devices can vibrate. The Vibration API allows Web apps the trigger vibration of the device (if its supported by the hardware).
Support by browsers and operating systems might be limited.
Single vibration
Vibrate the device for 100 ms:
const didVibrate = window.navigator.vibrate(100);
or
const didVibrate = window.navigator.vibrate([100]);
Check if vibration is supported
Check if browser supports vibrations
if ('vibrate' in window.navigator) {
// browser has support for vibrations
} else {
// no support
}
Vibration patterns
An array of values describes periods of time in which the device is vibrating and not vibrating.
window.navigator.vibrate([200, 100, 200]);
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents