Vibrate Your Mobile Phone Using jQuery Navigator Vibrate

Vibrate Your Mobile Phone Using jQuery Navigator Vibrate
File Size: 18.6 KB
Views Total: 155
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

A jQuery wrapper for the Navigator.vibrate() web API that allows you to trigger the device's vibration hardware directly from the web application.

How to use it:

1. Install & download the plugin.

# Yarn
$ yarn add jquery-navigator-vibrate

# NPM
$ npm install jquery-navigator-vibrate --save

2. Import the jQuery Navigator Vibrate plugin after jQuery.

<script src="/path/to/cdn/jquery.min.js"></script>
<script src="/path/to/lib/jquery-navigator-vibrate.js"></script>

3. Enable an trigger element to vibrate your mobile device.

<button class="example">
  Trigger Button
</button>
$(function(){
  $('.example').vibrate();
});>

4. Vibrate the device for 500 ms. Default: 300.

$('.example').vibrate({
  time: 500
});

5. You can also specify an array of values to alternately vibrate, pause, then vibrate again. In this example the plugin vibrates the device for 500 ms, then pauses for 200 ms before vibrating the device again for another 500 ms.

$('.example').vibrate({
  time: [500, 300, 500]
});

6. You can also specify an array of values to alternately vibrate, pause, then vibrate again. In this example the plugin vibrates the device for 500 ms, then pauses for 200 ms before vibrating the device again for another 500 ms.

$('.example').vibrate({
  time: [500, 300, 500]
});

7. Pulse the vibration hardware instead.

$('.example').vibrate({

  // default: 'constant'
  style: 'pulse', 

  // default 3
  pulseCount: 5,

  // default: 300
  pulseInterval: 500
  
});

8. Determine the trigger event. Default: 'click'.

$('.example').vibrate({
  event: 'touchstart'
});

9. Trigger a function after the vibration has been finished.

$('.example').vibrate({
  onVibrateComplete: function () {
    window.alert('Done!')
  }
});

This awesome jQuery plugin is developed by tinacious. For more Advanced Usages, please check the demo page or visit the official website.