Skip to content

Instantly share code, notes, and snippets.

@Jiab77
Forked from bohman/viewport.js
Last active January 6, 2017 22:09
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 Jiab77/26cecbec888fbc22e86735c69f14832d to your computer and use it in GitHub Desktop.
Save Jiab77/26cecbec888fbc22e86735c69f14832d 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 = window.innerHeight;
var width = window.innerWidth;
jQuery('body').prepend('<div id="viewportsize" style="z-index:9999;position:fixed;bottom:0px;left:0px;color:#fff;background:#000;padding:10px">Height: '+height+'<br>Width: '+width+'</div>');
jQuery(window).resize(function() {
height = window.innerHeight;
width = window.innerWidth;
jQuery('#viewportsize').html('Height: '+height+'<br>Width: '+width);
});
}
}
$(document).ready(function(){
showViewPortSize(true);
});
@Jiab77
Copy link
Author

Jiab77 commented Jan 6, 2017

Version based on the comment of @xmoonlight from this gist https://gist.github.com/bohman/1351439

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment