:heavy_dollar_sign: Vibration API Wrappers

Overview

This library was to be published hand-to-hand with my article on the Vibration API. You can also view the documentation.

Does my Device Support the API?

The vibration API is implemented in navigator.vibrate. So calling the function makes your phone vibrate. You can test if your browser is recent enough to have the vibrate function in navigator.

Mozilla had their own implementation mozVibrate so some browsers may support that instead.

var canVibrate = "vibrate" in navigator || "mozVibrate" in navigator;

if (canVibrate && !("vibrate" in navigator))
    navigator.vibrate = navigator.mozVibrate;

However, this doesn't mean that your device can vibrate. Just that it's recent enough. There are a few requirements you need to meet.

  1. You need the hardware for it.
  2. The page needs to be visible.
  3. Browser-specific implementation prevents the vibration.

Usage

jquery.vibrate.js

You can embed using bower with bower install jquery.vibrate.js. Or you can download the zip file and extract the build/jquery/* files.

The javascript files are located in build/jquery/jquery.vibrate.min.js.

Download and embed the code then initialize in one of the following ways.

// Vibration for 50ms on all .button on click
$(".button").vibrate();

// Vibrate for 20ms on click
$(".button").vibrate("short");

// Vibrate for 50ms on click
$(".button").vibrate("medium");
$(".button").vibrate("default");
$(".button").vibrate(50);

// Vibrate for 100ms on click
$(".button").vibrate("long");

// Vibrate for 40ms on touchstart
$(".button").vibrate({
    duration: 40,
    trigger: "touchstart"
});

// Vibrate twice
$(".button").vibrate({
    pattern: [20, 200, 20]
});

Development

I'm using grunt and node for building the docs. Grunt and jasmine for testing. Check out the gruntfile.

You might also like...

API Observability. Trace API calls and Monitor API performance, health and usage statistics in Node.js Microservices.

API Observability. Trace API calls and Monitor API performance, health and usage statistics in Node.js Microservices.

swagger-stats | API Observability https://swaggerstats.io | Guide Trace API calls and Monitor API performance, health and usage statistics in Node.js

Jan 4, 2023

A Weather API project inspired by The Ultimate API Challenge / Weather API.

Weather API Project A Weather API project inspired by The Ultimate API Challenge / Weather API. Tech Stack: React.js Tailwind Axios Inspiration The Pr

Dec 29, 2021

This project is built with JavaScript, Webpack, HTML & CSS, Leaderboard api. When user clicks on Refresh button it hits the api and responds with the data, The user can also post data to the api

This project is built with JavaScript, Webpack, HTML & CSS, Leaderboard api. When user clicks on Refresh button it hits the api and responds with the data, The user can also post data to the api

leaderboad Description the project. this project is about the leaderboad i did during Microverse to build a website for adding Data to the API and fet

May 30, 2022

🎉 Next Generation API-first CMS for developers. Generate an API-first CMS from a GraphQL schema with offline prototyping and an inline editor

🎉 Next Generation API-first CMS for developers. Generate an API-first CMS from a GraphQL schema with offline prototyping and an inline editor

Tipe Next Generation API-first CMS Design your content Shape and design content for any project you and your team are working on. Create your content

Oct 22, 2021

Single Page Application built using React, Context API and OMDb API.

Single Page Application built using React, Context API and OMDb API.

Movie Search App This project is a React application with functions to search for movies and add movies to favorites using OMDb API. Home Page Favorit

Sep 6, 2022

Different Widgets: Accordion, Search from Wikipedia(Wiki API), DropDown, Translate(Google API)

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: ya

Dec 19, 2021

Unofficial API client for the Tidbyt API. Use this client to control Tidbyt devices and integrate with other services.

Tidbyt Client for Node.js Unofficial API client for the Tidbyt API. Use this client to control Tidbyt devices and integrate with other services. Insta

Dec 17, 2022

Webb-tracker-api - James Webb Space Telescope (JWST) tracking REST API

Webb-tracker-api - James Webb Space Telescope (JWST) tracking REST API

James Webb Telescope tracking REST API Public REST API to track JWST's current status API data source: https://www.jwst.nasa.gov/content/webbLaunch/wh

Nov 22, 2022

To-do-expressJS-api - An ExpressJS API, where you can create your own To-Do's

To-do-expressJS-api - An ExpressJS API, where you can create your own To-Do's

ExpressJS to-do API What is this API about? This is an API where you can do the following: Log in. Sign up. Create task Read Task Update Task Delete T

Jan 3, 2022

Base-mock-api - Repo to storage my fake api's to use in my 2022 projects.

Base Mock API's Project made 100% with JavaScript, with the objective of creating endpoints to use in projects. Prerequisites Before you begin, ensure

Nov 20, 2022

Ts-api - This is a Typescript library facilitating usage of Localazy's API.

@localazy/ts-api This is a Typescript library facilitating usage of Localazy's API. To better understand this library, it is recommended to study the

Jun 17, 2022

Lolis-rest - RESTful API for lolis-api

Lolis REST RESTful + Website for Lolis API. Introduction This is a RESTful API which will be used on Lolis API Website and Wrapper. This API uses Imgu

Aug 11, 2022

JavaScript API based capstone project using TVmaze API for displaying and interacting with items from the data base.

JavaScript API based capstone project using TVmaze API for displaying and interacting with items from the data base.

Yuriy Chamkoriyski & Bonke Gcobo Javascript capstone project API-based webapp from Module 2 at Microverse Wireframe requirements The Home Page low fid

May 30, 2022

An open source API wrapper for TechHost API.

TechHost API Wrapper An open source API wrapper for TechHost API. Badges Installation Install techhost-api-wrapper with npm. npm install techhost-api-

Jun 23, 2022

Weather Application built using ReactJs , OpenCage API and OpenWeatherMap API

Weather-bot Netlify Site Status : Weather application built using ReactJs, OpenCage Api and OpenWeatherMap Api Tech Stack and Dependencies Name Descri

Oct 17, 2022

Example CRUD API for API Fest'22. See Pull Requests for chapter 2 and 3

Example CRUD API for API Fest'22. See Pull Requests for chapter 2 and 3

Mar 2, 2022

The leaderboard website displays scores submitted by different players. It also allows you to submit your score. All data is preserved thanks to the external Leaderboard API service. Build with Html, CSS, JS, API, and Webpack.

The leaderboard website displays scores submitted by different players. It also allows you to submit your score. All data is preserved thanks to the external Leaderboard API service. Build with Html, CSS, JS, API, and Webpack.

Mar 11, 2022

Essa API tem como objetivo auxiliar na produção de documentação de métodos e design packs, fornecendo de maneira visual a documentação de cores para api's

Essa API tem como objetivo auxiliar na produção de documentação de métodos e design packs, fornecendo de maneira visual a documentação de cores para api's

DocColors-API Essa API tem como objetivo auxiliar na produção de documentação de métodos e design packs, fornecendo de maneira visual a documentação d

Feb 4, 2022
Comments
  • screen rubbish

    screen rubbish

    I wonder if you can help..

    I'm using the vibrate as such (simplified - so I have an image rollover and touch vibrate - works WONDERFULLY

    
    <script src="/js/jquery.vibrate.min.js"></script>
    
    <script>
    $(".lightup").vibrate("short");
    
    function restore_icon() {
            $(this).attr('src',$(this).attr('src').replace("_b.png",".png"));
        };
    
    $('.lightup').on('mousedown', function() {
        $(this).attr('src',$(this).attr('src').replace(".png","_b.png"));  
        setTimeout(restore_icon.bind(this),500);
        });
    </script>
    
    <div layout="row" layout-align="space-between" style="padding:0px; text-align: left; margin:2px; border:2px solid black;">
    <img class="lightup" src="http://www.scargill.net/icons/timed.png" ng-click="send({payload: 'p1dn' })" height="24px"/>
    </div>
    

    However... on a NON-mobile - my text ends up totally garbled... some bracket info which should only display as "P1: 01:00 T1:16c" before the image... ends up like this..

    {{"P1: "+ msg.payload.p1}} {{"T1: "+ msg.payload.t1 + "c"}}

    In my example above how could I test to ensure this only happens in a mobile - or is there something else wrong - it absolutely works a treat on an android mobile..

    opened by scargill 2
  • jQuery chain support

    jQuery chain support

    Hi,

    today I was trying to include your plugin and use it through jQuery.

    The way you've done it is superawesome but it has a logical bug that breaks everything if the browser doesn't support Vibration API.

    Practically on iOS and Safari for OSX my javascript is crashing because I cannot chain the call since you're not returning something. See this text example: http://jsbin.com/biqeruwume/1/

    The affected line is this one, you're just returning something if Vibration API is there, while you should return always but do you stuff if you can do ( likely in your case, if you can use Vibration API ): https://github.com/Illyism/jquery.vibrate.js/blob/master/src/coffee/jquery.vibrate.coffee#L49

    Thanks in advice!

    opened by julianxhokaxhiu 2
  • Does not work on FireFox mobile browsers

    Does not work on FireFox mobile browsers

    I installed the FireFox browser on my iPhone 5s and attempted to try the demo here: https://illyism.github.io/jquery.vibrate.js/ (I did this because the following MDN link explains that it's only supported on FireFox: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate)

    However, upon clicking the various "try it" buttons on the page, the vibration never occurred. Please let me know if there are additional device settings that need to be in place.

    opened by jeffreysbrother 0
  • No example for a custom event

    No example for a custom event

    Would be beneficial to provide an example on custom events. The trigger parameter can be overwritten, thus can be assigned any event. I presume an example of this would be beneficial, as the only way I discovered this was possible was by inspecting the code. Going to test it first, and then post an example.

    $(document).vibrate({trigger:"someCustomEvent"});
    $(document).trigger("someCustomerEvent");
    

    Tested and working on Chrome. May work with $.vibrate but didn't examine the code closely enough.

    This issue was changed upon inspecting the code

    opened by dskvr 1
🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API

Huge thanks to for sponsoring me! Ky is a tiny and elegant HTTP client based on the browser Fetch API Ky targets modern browsers and Deno. For older b

Sindre Sorhus 8.5k Jan 2, 2023
A prebuilt Express JS Authentication & Authorization Project based on a REST API interface.

A prebuilt Express JS Authentication & Authorization Project based on a REST API interface. It has the basic authentication and Authorization routes with the latest security measures implemented so that your application is much more secure from day 1. You are welcome to build upon and extend this project as and when required.

Soumalya Bhattacharya 2 Oct 7, 2022
🧠 100'den fazla gereksiz bilgi ile oluşturulmuş bir JSON API.

?? Gereksiz Bilgiler API 100'den fazla gereksiz bilgi ile oluşturulmuş bir JSON API.

Orhan Emre Dikicigil 3 Sep 23, 2022
Fullstack nest (API/Monitering/machine learning, etc)

My backend nestjs requirement nodejs v16.13.1 checkpoint [devOnly] test connection to influx for monitoring (remaining security config) [devOnly] stes

NinetyNineNineTeenTales 2 Jan 18, 2022
API for managing authentication, creating Users, Items and Categories for FinancesApp

This is a repository to store all the API for managing authentication, creating users, items and categories. Search for single or multiple records at once, update items and categories and remove both.

Finances App 8 May 10, 2022
API routes are great for APIs, but for small projects where you have to access server data or hide application logic, you can just call a server function from the client.

API routes are great for APIs, but for small projects where you have to access server data or hide application logic, you can just call a server function from the client.

null 3 Mar 6, 2022
Building dynamic form in Angular with Fluent API

ngx-fluent-form Building dynamic form in Angular with Fluent API. Features Support using Fluent API and JSON. Type-safe form configuration.

HyperLifelll9 22 Dec 23, 2022
This web application retrieves real live data from the SpaceX API

This web application retrieves real live data from the SpaceX API. It provides commercial and scientific space travel services, by allowing users to book rockets and join selected space missions.

Sahar Abdel Samad 12 Aug 9, 2022
You can control the vibration capability of your device using the Vibration API. (JavaScript) This feature can useful in SPA and PWA.

Vibration Web API You can control the vibration capability of your device using the Vibration API. (JavaScript) This feature can useful in SPA and PWA

Max Base 2 Mar 29, 2022
This library was designed to be used in SPA framework wrappers for the FingerprintJS Pro Javascript Agent

Framework-agnostic SPA service wrapper. Use it to build a FingerprintJS Pro wrapper for your favorite framework.

FingerprintJS 12 Sep 3, 2022