Created
June 24, 2021 10:08
-
-
Save mike-at-redspace/8a66e017d420ff02b0e3234a8b4b0b02 to your computer and use it in GitHub Desktop.
Detect Touch
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
export function detectTouch() { | |
window.addEventListener('touchstart', function onFirstTouch() { | |
// we could use a class | |
document.body.classList.add('user-is-touching'); | |
// or set some global variable | |
// window.USER_IS_TOUCHING = true; | |
// or set your app's state however you normally would | |
// frameworkOfChoice.dispatchEvent('USER_IS_TOUCHING', true); | |
// we only need to know once that a human touched the screen, so we can stop listening now | |
window.removeEventListener('touchstart', onFirstTouch, false); | |
}, false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment