Home / Mobile / Vibration API
Vibration API

Vibration API

Download Demo
  • Overview
  • Documents
User Rating: 0/5 ( 0 votes)
Your Rating:

The Vibration API is an API specifically made for mobile devices as they are thankfullythe only devices that have a vibrate function. The API allows developers to vibrate a device (in a pattern) for a given duration.

The vibration API is implemented in navigator.vibrate. So calling the function makes your phone vibrate. You can test if your browser is recent enough to have thevibrate function in navigator.

Mozilla had their own implementation mozVibrate so some browsers may support that instead.

var canVibrate = "vibrate" in navigator || "mozVibrate" in navigator;

if (canVibrate && !("vibrate" in navigator))
    navigator.vibrate = navigator.mozVibrate;

However, this doesn't mean that your device can vibrate. Just that it's recent enough. There are a few requirements you need to meet.

  1. You need the hardware for it.
  2. The page needs to be visible.
  3. Browser-specific implementation prevents the vibration.
Scroll To Top