Skip to content

Instantly share code, notes, and snippets.

@dbox
Forked from rutger1140/viewportwidth.js
Created April 12, 2012 18:14
Show Gist options
  • Save dbox/2369768 to your computer and use it in GitHub Desktop.
Save dbox/2369768 to your computer and use it in GitHub Desktop.
Display viewport width with jQuery
/**
* Display your window width - useful for responsive web design
* @author: Rutger Laurman
*/
// Ready?
$(function(){
// Create debug element
$("body").append("<div style='position:absolute;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