pay-sdk-react
Version:
A cross-platform payment SDK for React, supporting Alipay, WeChat Pay, PayPal, Stripe, Payssion, and Airwallex, compatible with H5, PC, and App environments.
24 lines • 757 B
JavaScript
import { canUseDom } from "./can-use-dom";
const defaultRoot = canUseDom ? window : undefined;
const overflowStylePatterns = ["scroll", "auto", "overlay"];
function isElement(node) {
const ELEMENT_NODE_TYPE = 1;
return node.nodeType === ELEMENT_NODE_TYPE;
}
export function getScrollParent(el) {
let root = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 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;
}