Vibration API Sample

Available in Chrome 32+ | View on GitHub | Browse Samples

You can control the vibration capability of your device using the Vibration API. Chrome only supports this feature on Android devices.

JavaScript Snippet

function example1() {
  // Vibrate for 500ms
  navigator.vibrate([500]);
}

JavaScript Snippet

function example2() {
  // For a single value you can pass in a Number rather than an Array
  navigator.vibrate(500);
}

JavaScript Snippet

function startPattern() {
  // Values at even indices (0, 2, 4, ...) specify vibrations, while the odd
  // indices specify pauses.
  // Vibrate for 500ms 6 times, pausing for 250ms in between each one.
  navigator.vibrate([500, 250, 500, 250, 500, 250, 500, 250, 500, 250, 500]);
}

JavaScript Snippet

function stopVibrations() {
  // You can also stop an ongoing vibration pattern by specifying a vibration
  // length of zero.
  navigator.vibrate(0);
}