Last active
September 13, 2016 14:46
-
-
Save joonassandell/4ce9b660235fd7cd0054 to your computer and use it in GitHub Desktop.
Detect touch support
This file contains 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
/** | |
* Detect "touch" support and act accordingly. | |
* Adds `touch` class and assumes there is `no-touch` class added in <html> element. | |
*/ | |
let hasTouch = false; | |
const docEl = document.documentElement; | |
if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch || navigator.msMaxTouchPoints) { | |
docEl.className = docEl.className.replace(/(^|\s)no-touch(\s|$)/, ' touch '); | |
hasTouch = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment