Skip to content

Instantly share code, notes, and snippets.

Created September 22, 2018 04:02
What would you like to do?
export function detectTouch() {
// source
window.addEventListener('touchstart', function onFirstTouch() {
// we could use a class
// 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