Created
August 3, 2016 11:27
-
-
Save gre/296291b8ce0d8fe6e1c3ea4f1d1c5c3b 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
I think that
node.parentNode
on line 18 should benode.parentElement
, as getComputedStyle expects an Element rather than a Node.