Last active
May 12, 2023 12:03
-
-
Save c-kick/942ce38822c42ed4780ec264ca95b630 to your computer and use it in GitHub Desktop.
doubleClickHandler - handles double-click events on elements
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
/** | |
* Handles the click event to detect single or double clicks. | |
* @param {MouseEvent} event - The click event object. | |
*/ | |
function doubleClickHandler(event) { | |
const target = event.target; | |
if (new Date().getTime() - (target._lastTouch || 0) > 500) { | |
// Not a double click | |
target._lastTouch = new Date().getTime(); | |
event.preventDefault(); | |
} else { | |
// A double click | |
// Default event will proceed, do additional stuff here | |
} | |
} | |
// Attach the click event listener to the element with the ID 'doubleclick' | |
document.getElementById('doubleclick').addEventListener('click', doubleClickHandler); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment