Last active
May 13, 2023 05:39
-
-
Save toorajam/0c7fc1f9eeb854334757b56b497af43b to your computer and use it in GitHub Desktop.
Achieving double click event on a specific element on phone browsers.
This file contains hidden or 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
function doAnimation() { | |
// what ever | |
} | |
let clickCount = 0; | |
let timeout; | |
element.addEventListener("click", () => { | |
if (timeout) { | |
clearTimeout(timeout); | |
} | |
clickCount++; | |
if (clickCount === 2) { | |
doAnimation(); | |
clickCount = 0; | |
} | |
timeout = setTimeout(() => { | |
clickCount = 0; | |
}, 300); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working code on codesandbox.