Created
April 27, 2016 16:31
-
-
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.
This file contains 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
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