Skip to content

Instantly share code, notes, and snippets.

@sparkalow
Created April 27, 2016 16:31
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sparkalow/7ab0e37835abf6394e813651cc329ed9 to your computer and use it in GitHub Desktop.
Save sparkalow/7ab0e37835abf6394e813651cc329ed9 to your computer and use it in GitHub Desktop.
Useful JS snippet for finding DOM elements wider than current viewport. Only tested in Chrome.
var els = document.querySelectorAll('*');
var l = els.length;
var maxWidth = window.innerWidth;
console.log('Elements wider than ' + maxWidth);
for(var i = 0 ; i < l; i ++){
var e = els[i];
var width =e.offsetWidth;
rect = e.getBoundingClientRect();
if(rect.width > maxWidth){
var cssWidth = window.getComputedStyle(e, null).getPropertyValue("width");
console.log(width, cssWidth,e);
}
}
console.log("-------------\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment