Last active
August 29, 2015 13:57
-
-
Save kmaida/9348846 to your computer and use it in GitHub Desktop.
Function to check if matchMedia is supported; if so, use it, otherwise, use JS window width calculation (fixes issues with -webkit browsers returning incorrect window widths due to scrollbars)
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
function getviewport() { | |
var win = window, | |
matchMediaSupported = (win.matchMedia || win.msMatchMedia), | |
viewport; | |
if (matchMediaSupported) { | |
if (win.matchMedia('screen and (min-width: 641px)').matches) { | |
viewport = 'large'; | |
} else { | |
viewport = 'small'; | |
} | |
} else if (!matchMediaSupported && win.width > 640) { | |
viewport = 'large'; | |
} else { | |
viewport = 'small'; | |
} | |
return viewport; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment