Skip to content

Instantly share code, notes, and snippets.

@mammuth
Forked from davidgilbertson/detecting-touch.js
Created February 13, 2019 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mammuth/ac5a7027030ec900ec1c6128127bf933 to your computer and use it in GitHub Desktop.
Save mammuth/ac5a7027030ec900ec1c6128127bf933 to your computer and use it in GitHub Desktop.
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
myFrameworkOfChoice.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