Skip to content

Instantly share code, notes, and snippets.

@zmmbreeze
Created May 12, 2013 15:09
Show Gist options
  • Save zmmbreeze/5563867 to your computer and use it in GitHub Desktop.
Save zmmbreeze/5563867 to your computer and use it in GitHub Desktop.
function randomColor(){
return "rgb("+Math.floor(Math.random()*255)+","+Math.floor(Math.random()*255)+","+Math.floor(Math.random()*255)+")";
}
function showBoxes(window) {
var rects = [];
function getRects(node){
var range = window.document.createRange();
range.setStartBefore(node);
range.setEndAfter(node);
rects.push.apply(rects,range.getClientRects());
for(var i = 0; i < node.children.length; i++ )
getRects(node.children[i]);
}
getRects(window.document.documentElement);
window.document.documentElement.style.background = "url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\">"+rects.map(function(rect){
return "<rect x=\""+rect.left+"\" y=\""+rect.top+"\" width=\""+rect.width+"\" height=\""+rect.height+"\" style=\"fill:"+randomColor()+";fill-opacity:0.1;stroke:black;stroke-width:1;\"/>"
}).join("")+"</svg>') no-repeat";
window.onresize = function(){ showBoxes(window); };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment