April 2013
Intermediate to advanced
264 pages
7h 44m
English
The Vibration API makes a device vibrate, providing some haptic feedback for your users. This API actually used to be called the Vibrator API, but I’m sure you don’t need me to tell you why that name was changed very quickly. Obviously not all devices are capable of vibrating, especially larger ones, so this API is decidedly more useful in mobile devices.
The API is extremely simple, requiring only the vibrate() method on the navigator object. The value supplied to vibrate() is a figure representing the number of milliseconds for the device to vibrate; for example, to make the device vibrate for one-fifth of a second after the user has completed a touchend event, use this code:
document.addEventListener('touchend', function () { window.navigator.vibrate(200); ...Read now
Unlock full access