UNPKG

@nutui/nutui-react-taro

Version:

京东风格的轻量级移动端 React 组件库,支持一套代码生成 H5 和小程序

26 lines (25 loc) 814 B
const canUseDom = !!(typeof window !== "undefined" && typeof document !== "undefined" && window.document && window.document.createElement); const defaultRoot = canUseDom ? window : void 0; const overflowStylePatterns = ["scroll", "auto", "overlay"]; function isElement(node) { const ELEMENT_NODE_TYPE = 1; return node.nodeType === ELEMENT_NODE_TYPE; } function getScrollParent(el, root = defaultRoot) { let node = el; while (node && node !== root && isElement(node)) { if (node === document.body) { return root; } const { overflowY } = window.getComputedStyle(node); if (overflowStylePatterns.includes(overflowY) && node.scrollHeight > node.clientHeight) { return node; } node = node.parentNode; } return root; } export { canUseDom as c, getScrollParent as g };