What is vibration API in web APIs?
Vibration API
Vibration API makes a device shake or vibrate as a means of notification or physical feedback to new data or information that we should respond to.
The method that does this is the navigator.vibrate(pattern).
Parameter and working
The pattern parameter is a single number or an array of numbers that describes the vibration pattern.
navigator.vibrate(200)
navigator.vibrate([200])
This will make the device vibrate for 200ms and then stop.
navigator.vibrate([200, 300, 400])
This will make the device vibrate for 200ms, pause for 300ms, vibrate for 400ms, and then stop.
ms: milliseconds
Vibration can be cancelled by passing the 0, [], array full of zeroes [0,0,0].
Code
Let’s look at a simple demo.
Explanation
We have input and a button. Input the duration of the vibration in the input box and press the button.
Your device will vibrate for the amount of time that was fed as input.
Try it live here: Vibration API.
Free Resources
- undefined by undefined