mirror of
https://github.com/discourse/discourse.git
synced 2024-12-23 05:23:58 +08:00
14 lines
455 B
JavaScript
14 lines
455 B
JavaScript
|
export function getScrollParent(node) {
|
||
|
const isElement = node instanceof HTMLElement;
|
||
|
const overflowY = isElement && window.getComputedStyle(node).overflowY;
|
||
|
const isScrollable = overflowY !== "visible" && overflowY !== "hidden";
|
||
|
|
||
|
if (!node || node === document.documentElement) {
|
||
|
return null;
|
||
|
} else if (isScrollable && node.scrollHeight >= node.clientHeight) {
|
||
|
return node;
|
||
|
}
|
||
|
|
||
|
return getScrollParent(node.parentNode) || window;
|
||
|
}
|