Last active
June 6, 2018 08:00
-
-
Save sergixnet/8e2a29a893efac970491f9af38108ed7 to your computer and use it in GitHub Desktop.
This snippet detects if current device has a touch screen
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 devices | |
var isTouchDevice = function isTouchDevice() { | |
if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) { | |
return true; | |
} | |
return false; | |
} | |
if ( isTouchDevice()) { | |
document.body.classList.add('touch-device'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment