Skip to content

Instantly share code, notes, and snippets.

@brunomonteiro3
Forked from thiagoeliasr/viewportsize.js
Last active April 8, 2022 19:57
Show Gist options
  • Save brunomonteiro3/68c5bdf77b815754baf7 to your computer and use it in GitHub Desktop.
Save brunomonteiro3/68c5bdf77b815754baf7 to your computer and use it in GitHub Desktop.
Display ViewPort and Screen Resolution at the top of screen. (This script was created intended to be a bookmarklet)
$(document).find('body').append('<div id="div-width-top" style="position: fixed; right: 5px; top: 5px; background: #000; color: #fff; padding: 10px; z-index: 99999; opacity: 0.7">Window Size:</div>');
$('#div-width-top').html('ViewPort: ' + window.innerWidth + 'px | Window: ' + screen.width + 'px');
$(window).resize(function() {
$('#div-width-top').html('ViewPort: ' + window.innerWidth + 'px | Window: ' + screen.width + 'px');
});
@brunomonteiro3
Copy link
Author

Alternative version:
javascript:(function()%7Bfunction%20callback()%7B(function(%24)%7Bvar%20jQuery%3D%24%3B%24(document).find(%22body%22).append('%3Cdiv%20id%3D%22div-width-top%22%20style%3D%22position%3A%20fixed%3B%20right%3A%205px%3B%20top%3A%205px%3B%20background%3A%20%23000%3B%20color%3A%20%23fff%3B%20padding%3A%2010px%3B%20z-index%3A%2099999%3B%20opacity%3A%200.7%22%3EWindow%20Size%3A%3C%2Fdiv%3E')%2C%24(%22%23div-width-top%22).html(%22Largura%3A%20%22%2Bwindow.innerWidth%2B%22px%20%7C%20Altura%3A%20%22%2Bwindow.innerHeight%2B%22px%22)%2C%24(window).resize((function()%7B%24(%22%23div-width-top%22).html(%22Largura%3A%20%22%2Bwindow.innerWidth%2B%22px%20%7C%20Altura%3A%20%22%2Bwindow.innerHeight%2B%22px%22)%7D))%7D)(jQuery.noConflict(true))%7Dvar%20s%3Ddocument.createElement(%22script%22)%3Bs.src%3D%22https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fjquery%2F1.11.1%2Fjquery.min.js%22%3Bif(s.addEventListener)%7Bs.addEventListener(%22load%22%2Ccallback%2Cfalse)%7Delse%20if(s.readyState)%7Bs.onreadystatechange%3Dcallback%7Ddocument.body.appendChild(s)%3B%7D)()

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