-
-
Save baamenabar/0e62174c75695fed50a1 to your computer and use it in GitHub Desktop.
Detect touch and no-touch devices.
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
// 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