May 21, 2021 Cordova
This plug-in is used to connect the vibration function of the device.
We can install this plug-in in the command prompt window by running the following code:
C:\Users\username\Desktop\CordovaProject>cordova plugin add cordova-plugin-vibration
After installing the plug-in, we .html buttons in the index code and will be used to trigger vibrations later.
<button id = "vibration">VIBRATION</button> <button id = "vibrationPattern">PATTERN</button>
Now we'.js add an event listener within onDeviceReady in index data.
document.getElementById("vibration").addEventListener("click", vibration); document.getElementById("vibrationPattern").addEventListener("click", vibrationPattern);
This is a plug-in that is very easy to use. /b10> We'll create two functions.
function vibration() { var time = 3000; navigator.vibrate(time); } function vibrationPattern() { var pattern = [1000, 1000, 1000, 1000]; navigator.vibrate(pattern); }
The first feature is to use the Time parameter. /b10> This parameter is used to set the duration of the vibration. /b11> Once the VIBRATION button is pressed, the device vibrates for three seconds.
The second function is to use the pattern parameter. /b10> This array will require the device to vibrate for one second, then wait one second, and then repeat the process.