Last active
August 29, 2015 14:02
-
-
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
O Paulo Diovani fez uma versão melhor e muito mais elegante.