Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
isTouchDevice
const isTouchDevice = () => {
const prefixes = ['', '-webkit-', '-moz-', '-o-', '-ms-', ''];
const mq = query => window.matchMedia(query).matches;
if (
'ontouchstart' in window ||
(window.DocumentTouch && document instanceof 'DocumentTouch')
) {
return true;
}
return mq(['(', prefixes.join('touch-enabled),('), 'heartz', ')'].join(''));
};
if (isTouchDevice()) {
document.body.classList.add("touch");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment