Skip to content

Instantly share code, notes, and snippets.

@toorajam
Last active May 13, 2023 05:39
Show Gist options
  • Save toorajam/0c7fc1f9eeb854334757b56b497af43b to your computer and use it in GitHub Desktop.
Save toorajam/0c7fc1f9eeb854334757b56b497af43b to your computer and use it in GitHub Desktop.
Achieving double click event on a specific element on phone browsers.
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);
})
@toorajam
Copy link
Author

Working code on codesandbox.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment