Created
August 4, 2023 14:09
-
-
Save migreva/50df6da992229c27535f0f22a9c7ac28 to your computer and use it in GitHub Desktop.
get all elements that have a scrollbar
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
// 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