Skip to content

Instantly share code, notes, and snippets.

@migreva
Created August 4, 2023 14:09
Show Gist options
  • Save migreva/50df6da992229c27535f0f22a9c7ac28 to your computer and use it in GitHub Desktop.
Save migreva/50df6da992229c27535f0f22a9c7ac28 to your computer and use it in GitHub Desktop.
get all elements that have a scrollbar
// copied from this SO post here:
// https://stackoverflow.com/a/27822785/1337683
function isScroller(el) {
var isScrollableWidth, isScollableHeight, elStyle;
elStyle = window.getComputedStyle(el, null); // Note: IE9+
if (elStyle.overflow === 'scroll' ||
elStyle.overflowX === 'scroll' ||
elStyle.overflowY === 'scroll') {
return true;
}
if (elStyle.overflow === 'auto' ||
elStyle.overflowX === 'auto' ||
elStyle.overflowY === 'auto') {
if (el.scrollHeight > el.clientHeight) {
return true;
}
if (el.scrollWidth > el.clientWidth) {
return true;
}
}
return false;
}
var els = document.querySelectorAll('body *');
for (var i = 0, el; el = els[i]; i++) {
if (isScroller(el)) {
console.log(el);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment