From 446e2f292ccc58fe225fbaabdde398310758f792 Mon Sep 17 00:00:00 2001 From: ajaxzheng <894103554@qq.com> Date: Fri, 9 May 2025 15:24:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(popper):=20=E5=A2=9E=E5=BC=BAisScrollElemen?= =?UTF-8?q?t=E5=87=BD=E6=95=B0=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=AF=B9?= =?UTF-8?q?=E5=85=83=E7=B4=A0=E7=B1=BB=E5=9E=8B=E5=92=8C=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E6=9D=A1=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/utils/src/popper/index.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/utils/src/popper/index.ts b/packages/utils/src/popper/index.ts index 4da24ec789..9767f5f820 100644 --- a/packages/utils/src/popper/index.ts +++ b/packages/utils/src/popper/index.ts @@ -99,13 +99,19 @@ const getBoundingClientRect = (el: HTMLElement) => { /** 判断el的overflow是不是可能滚动的 */ const isScrollElement = (el: HTMLElement) => { - const scrollTypes = ['scroll', 'auto'] + if (!el || el.nodeType !== 1) { + return false + } + // 针对overflow的判断,并且增加了对元素是否有滚动条的判断 + const css = window.getComputedStyle(el, null) + const overflow = css.overflow + const overflowX = css.overflowX + const overflowY = css.overflowY + const pattern = /(auto|scroll|overlay|clip)/ + + const hasScrollableContent = el.scrollHeight > el.clientHeight || el.scrollWidth > el.clientWidth - return ( - scrollTypes.includes(getStyleComputedProperty(el, 'overflow')) || - scrollTypes.includes(getStyleComputedProperty(el, 'overflow-x')) || - scrollTypes.includes(getStyleComputedProperty(el, 'overflow-y')) - ) + return hasScrollableContent && pattern.test(overflow + overflowY + overflowX) } /** 设置transform等样式后,fixed定位不再相对于视口,使用1X1PX透明元素获取fixed定位相对于视口的修正偏移量。 */