Recipe 14.6
Making the Device Vibrate
Compatibility Note: Vibration API
This feature may not be supported on all browsers yet. Please check the latest compatibility data before using in a production application.
Browser support for Vibration APIThe navigator.vibrate
method, on supported devices, lets you make the device vibrate to call attention to the user.
You can trigger a single vibration, or a sequence of vibrations and pauses.
Code
JavaScript
// A single vibration for 500ms
navigator.vibrate(500);
// A pattern of multiple vibrations
// Vibrate for 500ms three times, with a 250ms pause in between
navigator.vibrate([500, 250, 500, 250, 500]);