Last active
January 22, 2018 22:02
-
-
Save Beaglefoot/73ba60c4acefdf245ce14d6341b620e1 to your computer and use it in GitHub Desktop.
Find elements whose width is greater than window.innerWidth, possibly resulting in appearance of horizontal scroll.
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
// Throw this into dev console and set 'max-width: 100%' for returned list of elements | |
Array.from(document.querySelectorAll('*')).filter(el => { | |
if (el.getBoundingClientRect().width > window.innerWidth) return true; | |
const { | |
width, | |
paddingLeft, | |
paddingRight, | |
marginLeft, | |
marginRight | |
} = getComputedStyle(el); | |
return [ | |
width, | |
paddingLeft, | |
paddingRight, | |
marginLeft, | |
marginRight | |
].reduce((sum, val) => sum + parseInt(val), 0) > window.innerWidth; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment