Skip to content

Instantly share code, notes, and snippets.

@jtechera
Last active May 11, 2017 16:44
Show Gist options
  • Save jtechera/8b22f1adea98f563cdc8eeca6c994c9b to your computer and use it in GitHub Desktop.
Save jtechera/8b22f1adea98f563cdc8eeca6c994c9b to your computer and use it in GitHub Desktop.
/*If you are using jQuery, you can get the size of the window or the document using jQuery methods:*/
$(window).height(); // returns height of browser viewport
$(document).height(); // returns height of HTML document (same as pageHeight in screenshot)
$(window).width(); // returns width of browser viewport
$(document).width(); // returns width of HTML document (same as pageWidth in screenshot)
/*For screen size you can use the screen object in the following way:*/
screen.height;
screen.width;
/* Wihout jQuery */
var width = window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;
var height = window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment