Google News
logo
HTML5 - Interview Questions
What is Vibration API in HTML5?
Vibration is a simple, nice way of alert when you get a new message or a phone call. It is especially useful when you are in a noisy environment or the place where you feel the ringing would be a distraction to others.
 
It is interesting to know that HTML5 is now providing us to play with the vibration on the devices but the HTML5 Vibrate API supports only the recent version of Firefox & Chrome.
 
To check the vibration, API support in browsers as shown below,

navigator.vibrate = navigator.vibrate || navigator.mozVibrate ||  
navigator.webkitVibrate || navigator.msVibrate;  
if (navigator.vibrate) {  
   // supports vibration API.  
}  

Vibration Syntax : Vibration basic syntax is,
 
navigator.vibrate(long | [long]);
 
The vibrate function accepts milliseconds or an array of milliseconds.
 
Example
// vibrate for 1000 ms  
navigator.vibrate(1000);  
// same like above but in array of ms  
navigator.vibrate([1000]);  
In the above examples, we are setting the device to vibrate 1000 milliseconds.
Advertisement