-
-
Save johnloy/e0de7d6a33608bb4d92bb17839fdcc5d 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 style = (node, prop) => | |
getComputedStyle(node, null).getPropertyValue(prop); | |
const scroll = (node) => | |
regex.test( | |
style(node, "overflow") + | |
style(node, "overflow-y") + | |
style(node, "overflow-x")); | |
const scrollparent = (node) => | |
!node || node===document.body | |
? document.body | |
: scroll(node) | |
? node | |
: scrollparent(node.parentNode); | |
export default scrollparent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment