TIL how to make mobile devices vibrate
POSTED ON:
TAGS: javascript mobile
This is using the Vibration API.
The Navigator.vibrate() method pulses the vibration hardware on the device, if such hardware exists. If the device doesn't support vibration, this method has no effect. If a vibration pattern is already in progress when this method is called, the previous pattern is halted and the new one begins instead.
navigator.vibrate(200); // vibrate for 200ms
navigator.vibrate([100,30,100,30,100,30,200,30,200,30,200,30,100,30,100,30,100]); // Vibrate 'SOS' in Morse.
It currently doesn't work on a few desktop browser types. But it's great on mobile.
https://caniuse.com/vibration
Related TILs
Tagged: javascript