From f72b8c7614135382bea9899a86b2ab1cb0db761b Mon Sep 17 00:00:00 2001 From: i33 <78162524@qq.com> Date: Tue, 21 Jun 2022 12:51:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3getScrollParent?= =?UTF-8?q?=E9=80=BB=E8=BE=91=20(#141)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Create const.ts 错别字 * docs:修改注释中错别字 * fix: 修正getScrollParent逻辑 --- packages/stage/src/util.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/stage/src/util.ts b/packages/stage/src/util.ts index 4ab4c3f23..9a5ceeaaf 100644 --- a/packages/stage/src/util.ts +++ b/packages/stage/src/util.ts @@ -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; }