Last active
August 29, 2015 14:05
-
-
Save jfitzsimmons2/104b8a179013a53bec14 to your computer and use it in GitHub Desktop.
Accurately returns the height and width of the viewport much more reliably than $(window).height
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
/* | |
* Accurately returns the height and width of the viewport | |
* much more reliably than simply $(window).height | |
* | |
* Source: http://andylangton.co.uk/blog/development/get-viewport-size-width-and-height-javascript | |
*/ | |
function viewport() { | |
var e = window, a = 'inner'; | |
if ( !( 'innerWidth' in window ) ) { | |
a = 'client'; | |
e = document.documentElement || document.body; | |
} | |
return { width : e[ a+'Width' ] , height : e[ a+'Height' ] } | |
} | |
function is_mobile() { | |
if (viewport().width < 768) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment