Skip to content

Instantly share code, notes, and snippets.

@manfromanotherland
Last active August 29, 2015 14:02
Show Gist options
  • Save manfromanotherland/82712f8250ecd21ba18f to your computer and use it in GitHub Desktop.
Save manfromanotherland/82712f8250ecd21ba18f to your computer and use it in GitHub Desktop.
JS: Show viewport size for easy responsive development (no need to have the dev tools open).
// Show viewport size
document.addEventListener('DOMContentLoaded', function() {
document.body.insertAdjacentHTML('afterend', '<div id="viewport-size" style="position:fixed; top:0; right:0; z-index: 9999; padding:0 .5em; color:#333; background:rgba(255,255,255,.75); font: 14px/1.8em Monaco, Inconsolata, Ubuntu Mono, Courier New, monospaced;"></div>');
showViewportSize();
});
window.onresize = function() { showViewportSize(); }
function showViewportSize() {
var body = document.body,
html = document.documentElement,
width = Math.max( html.clientWidth, window.innerWidth ),
height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight );
document.getElementById('viewport-size').innerHTML = width + ' × ' + height;
}
@manfromanotherland
Copy link
Author

O Paulo Diovani fez uma versão melhor e muito mais elegante.

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