Created
May 9, 2013 21:19
-
-
Save booknara/5550708 to your computer and use it in GitHub Desktop.
Prevent Single Clicks when double clicks is fired.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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