fix: 修正getScrollParent逻辑 (#141)

* Create const.ts

错别字

* docs:修改注释中错别字

* fix: 修正getScrollParent逻辑
This commit is contained in:
i33 2022-06-21 12:51:35 +08:00 committed by GitHub
parent b751621488
commit f72b8c7614
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -118,15 +118,17 @@ export const getMode = (el: HTMLElement): Mode => {
export const getScrollParent = (element: HTMLElement, includeHidden = false): HTMLElement | null => {
let style = getComputedStyle(element);
const excludeStaticParent = style.position === 'absolute';
const overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/;
if (isFixed(element)) return null;
if (style.position === 'fixed') return null;
for (let parent = element; parent.parentElement; ) {
parent = parent.parentElement;
style = getComputedStyle(parent);
if (isAbsolute(element) && isStatic(element)) {
continue;
}
if (excludeStaticParent && style.position === 'static') continue;
if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX)) return parent;
}