Vibration API

suggest change

Modern mobile devices can vibrate. The Vibration API lets a web page trigger vibration when the hardware supports it. A browser can expose vibrate and still refuse the request, in which case the call returns false.

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 millisecond values alternates vibration and pause, starting with vibration. [200, 100, 200] vibrates for 200 ms, pauses for 100 ms, then vibrates for 200 ms.

window.navigator.vibrate([200, 100, 200]);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents