Created
July 27, 2017 18:13
-
-
Save rbk/c7162fd43d74a1a94ae3691743d9b642 to your computer and use it in GitHub Desktop.
Find out if any elements are wider that the screen size.
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
function findElementsLargerThanScreen() { | |
var elements = document.querySelectorAll('*') | |
for (var i = 0; i < elements.length; i++) { | |
var elementWidthInt = 0; | |
var elementWidth = window.getComputedStyle(elements[i], null).width | |
if (elementWidth !== 'auto') { | |
elementWidthInt = parseFloat(elementWidth.replace('px', '')); | |
if (elementWidthInt > screen.width) { | |
console.log(elementWidthInt) | |
} else { | |
console.log('no') | |
} | |
} | |
} | |
} | |
findElementsLargerThanScreen() | |
document.addEventListener('click', findElementsLargerThanScreen) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment