Skip to content

Instantly share code, notes, and snippets.

@booknara
Created May 9, 2013 21:19
Show Gist options
  • Save booknara/5550708 to your computer and use it in GitHub Desktop.
Save booknara/5550708 to your computer and use it in GitHub Desktop.
Prevent Single Clicks when double clicks is fired.
// Preventing single click when double-click is fired
var DELAY = 300, clicks = 0, time = null;
function handleSingleEvent(event)
{
clicks++;
if (clicks == 1)
{
timer = setTimeout( function() {
// performing action
clicks = 0; // after action performed, reset counter
}, DELAY);
} else {
clearTimeout(timer); // prevent single-click aciton
console.log("double click is fired"); // action
clicks = 0; // after action performed, reset counter
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment