JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<div class="container">
<button>click here</button>
<p></p>
<span></span>
</div>
JavaScript
var DELAY = 3050, //3050ms
clicks = 0;
// Detect double click
$('.container button').on('dblclick', function(e) {
$('span').html('Double click event');
$('span').fadeOut('15000');
});
// Detect two consecutive clicks
$('.container button').on('click', function (e) {
$('p').html('');
clicks++;
// myInterval function is timer which will continue to check
// if the time between 1st & 2nd click is in between 1200 and 3050,
// then it is slow double click.
var start = new Date();
var myInterval = setInterval(
function(){
var end = new Date();
var time = end.getTime() - start.getTime();
if((time > 1000 && time <= DELAY) && clicks == 2) {
$('p').html('two consecutive clicks');
clicks = 0;
}
// Reset Timer.
if(time > DELAY || clicks == 2){
clicks = time = 0;
clearInterval(myInterval);
$('p').html('');
console.log("if double clicked, control shouldn't come here");
}
}, 600);
});