Skip to content

Instantly share code, notes, and snippets.

@baamenabar
Forked from nikoskip/gist:f6ee7b8191945b97adaf
Last active August 29, 2015 14:04
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 baamenabar/0e62174c75695fed50a1 to your computer and use it in GitHub Desktop.
Save baamenabar/0e62174c75695fed50a1 to your computer and use it in GitHub Desktop.
Detect touch and no-touch devices.
// It will add the appropriate class to <html> node
// This should only be used in combination with media queries detecting wide screens, because it is not reliable.
// Always use with a mobile-first approach
var root = document.documentElement;
if(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
root.className += ' touch';
} else {
root.className += ' no-touch';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment