JQuery is required to run this plugin, which is an extension of one of its methods.
Use on command line:
npm install [-g] jquery.longclicks
or insert this line in the <head> tag of your JS file:
<script src="https://cdn.jsdelivr.net/npm/jquery.longclicks@1.0.0/plugin/jquery.longclicks.min.js"></script>or download manually jquery.longclicks[.min].js from Plugin folder.
The plugin allows to call the JQuery on method with three new events shortClick, longClick and shortClickReached, as shown below:
$('#element').mayTriggerLongClicks({
shortDelay: 400, longDelay: 800
// Usual JQuery "click" option
}).on('click', function() {
console.log('The click lasted less than 400ms');
// Is triggered as soon as the short click is reached and can be triggered
}).on('shortClickReached', function() {
console.log('The click lasted at least 400ms');
// Is triggered if the short delay is reached and the click is released before the long delay is reached
}).on('shortClick', function() {
console.log('The click lasted between 400ms and 799ms');
// Is triggered as soon as the long delay is reached. This auto cancels the short click trigger
}).on('longClick', function() {
console.log('The click lasted at least 800ms');
});Two optional parameters shortDelay and longDelay allow to define the delay before each click is triggered.
By default, shortDelay is defined to 300ms and longDelay is defined to 800ms.
Note that if the longDelay value is lower than shortDelay, shortDelay and shortClickReached will never be triggered.
This repo is a fork of the original untill (Till Halbach) plugin that offered one long click which can be found here: https://github.com/untill/jquery.longclick