Created
November 19, 2019 00:29
-
-
Save stphn/2fc17ad9dd7a2de089ef02c43d2783b1 to your computer and use it in GitHub Desktop.
Detect 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
export const isTouchDevice = () => { | |
let prefixes = ' -webkit- -moz- -o- -ms- '.split(' ') | |
let mq = function(query) { | |
return window.matchMedia(query).matches | |
} | |
if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) { | |
return true | |
} | |
// include the 'heartz' as a way to have a non matching MQ to help terminate the join | |
// https://git.io/vznFH | |
let query = ['(', prefixes.join('touch-enabled),('), 'heartz', ')'].join('') | |
return mq(query) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment