Skip to content

Instantly share code, notes, and snippets.

@mrtonyhuynh
Forked from bohman/viewport.js
Created May 27, 2016 02:27
Show Gist options
  • Save mrtonyhuynh/04459e35d9daaca98e26faea40321d62 to your computer and use it in GitHub Desktop.
Save mrtonyhuynh/04459e35d9daaca98e26faea40321d62 to your computer and use it in GitHub Desktop.
jQuery get viewport size
// -----------
// Debugger that shows view port size. Helps when making responsive designs.
// -----------
function showViewPortSize(display) {
if(display) {
var height = jQuery(window).height();
var width = jQuery(window).width();
jQuery('body').prepend('<div id="viewportsize" style="z-index:9999;position:fixed;top:40px;left:5px;color:#fff;background:#000;padding:10px">Height: '+height+'<br>Width: '+width+'</div>');
jQuery(window).resize(function() {
height = jQuery(window).height();
width = jQuery(window).width();
jQuery('#viewportsize').html('Height: '+height+'<br>Width: '+width);
});
}
}
showViewPortSize(true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment