Created
April 12, 2012 10:03
-
-
Save rutger1140/2366187 to your computer and use it in GitHub Desktop.
Display viewport width with jQuery
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
/** | |
* Display your window width - useful for responsive web design | |
* @author: Rutger Laurman | |
*/ | |
// Ready? | |
$(function(){ | |
// Create debug element | |
$("body").append("<div style='position:fixed;top:0;left:0;border:1px solid #999;background:#eee;' id='viewportwidth'></div>"); | |
// Set contents on resizing window | |
$(window).resize(function(){$("#viewportwidth").html($(window).width());}); | |
// Trigger resize event | |
$(window).resize(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@joshintosh Maybe it has something to do with browserbars or the padding on your
html
orbody
tag. Does it do the same with other websites?Also this snippet evolved into this: https://gist.github.com/lekkerduidelijk/3060429
Do check out @roelven his version, it's more stable than mine: https://gist.github.com/lekkerduidelijk/3060429#comment-757435