You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
546 B

2 months ago
  1. import getParentNode from "./getParentNode.js";
  2. import isScrollParent from "./isScrollParent.js";
  3. import getNodeName from "./getNodeName.js";
  4. import { isHTMLElement } from "./instanceOf.js";
  5. export default function getScrollParent(node) {
  6. if (['html', 'body', '#document'].indexOf(getNodeName(node)) >= 0) {
  7. // $FlowFixMe[incompatible-return]: assume body is always available
  8. return node.ownerDocument.body;
  9. }
  10. if (isHTMLElement(node) && isScrollParent(node)) {
  11. return node;
  12. }
  13. return getScrollParent(getParentNode(node));
  14. }