-
-
Save krutoo/4b2c6c81be872fee2a4a3b640373e519 to your computer and use it in GitHub Desktop.
get first parent scrollable container of a DOM element
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
// more minimal version of https://github.com/olahol/scrollparent.js/blob/master/scrollparent.js | |
const regex = /(auto|scroll)/; | |
const isScrollable = element => { | |
let result = false; | |
if (element) { | |
const styles = getComputedStyle(element); | |
result = regex.test(styles.overflow + styles.overflowX + styles.overflowY); | |
} | |
return result; | |
} | |
const getScrollParent = element => !element || element === document.body | |
? document.body | |
: isScrollable(element.parentElement) | |
? element.parentElement | |
: getScrollParent(element.parentElement); | |
export { getScrollParent }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment