Skip to content

Commit

Permalink
fix: 修正getScrollParent逻辑 (#141)
Browse files Browse the repository at this point in the history
* Create const.ts

错别字

* docs:修改注释中错别字

* fix: 修正getScrollParent逻辑
  • Loading branch information
isensen authored Jun 21, 2022
1 parent b751621 commit f72b8c7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/stage/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit f72b8c7

Please sign in to comment.