Skip to content

Instantly share code, notes, and snippets.

@jfitzsimmons2
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfitzsimmons2/104b8a179013a53bec14 to your computer and use it in GitHub Desktop.
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
/*
* 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