Skip to content

Instantly share code, notes, and snippets.

@matrixwd
Last active January 20, 2020 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matrixwd/d1fc4b0cd8c6343f82ab1d421ce86ae5 to your computer and use it in GitHub Desktop.
Save matrixwd/d1fc4b0cd8c6343f82ab1d421ce86ae5 to your computer and use it in GitHub Desktop.
/*
* This script helps identify what element is causing a horizontal scroll.
* Simply paste this into the console of Chrome, FF, etc...
* This was from CSS-Tricks back in 2014 but still works like a charm today
* https://css-tricks.com/findingfixing-unintended-body-overflow/
*/
var all = document.getElementsByTagName("*"), i = 0, rect, docWidth = document.documentElement.offsetWidth;
for (; i < all.length; i++) {
rect = all[i].getBoundingClientRect();
if (rect.right > docWidth || rect.left < 0){
console.log(all[i]);
all[i].style.border = '1px solid red';
}
}
/*
* Like above, his script helps identify what element inside a iframe that is causing a horizontal scroll.
* Simply paste this into the console of Chrome, FF, etc...
*/
var frame = document.getElementsByTagName("iframe");
frame = frame[0];
frame = (frame.contentWindow || frame.contentDocument);
var all = frame.document.getElementsByTagName("*"), i = 0, rect, docWidth = document.documentElement.offsetWidth;
for (; i < all.length; i++) {
rect = all[i].getBoundingClientRect();
if (rect.right > docWidth || rect.left < 0){
console.log(all[i]);
all[i].style.border = '1px solid red';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment