stephenjbell

Display current page width in px and ems - jQuery

Jul 18th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.45 KB | None | 0 0
  1. $(document).ready(function() {
  2.     $("<div id='screenwidth' style='position:fixed;right:0;bottom:0;background-color:#339;color:#fff;padding:3px;font-size:9px;'></div>").appendTo("body");
  3.  
  4.     function getWindowSize(){
  5.         var windowWidth = $(window).width();
  6.         var windowWidthEms = windowWidth / 16;
  7.         $("#screenwidth").text(windowWidth+"px, "+Math.round(windowWidthEms)+"em");
  8.     }
  9.  
  10.     getWindowSize();
  11.  
  12.     $(window).resize(function() {
  13.         getWindowSize();
  14.     });
  15. });
Advertisement
Add Comment
Please, Sign In to add comment