From f1918b4bb88f3bd8313612f270fb96c0dbc1980e Mon Sep 17 00:00:00 2001 From: pany <939630029@qq.com> Date: Fri, 1 Sep 2023 23:01:52 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=85=A8=E5=B1=80=E6=B0=B4=E5=8D=B0?= =?UTF-8?q?=E9=87=87=E7=94=A8=20fixed=20=E5=B8=83=E5=B1=80=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E5=85=BC=E5=AE=B9=E6=9B=B4=E5=A4=9A=E7=9A=84=E7=BB=86?= =?UTF-8?q?=E8=8A=82=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useWatermark.ts | 7 +++++-- src/styles/index.scss | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/hooks/useWatermark.ts b/src/hooks/useWatermark.ts index ae05f20..87483bd 100644 --- a/src/hooks/useWatermark.ts +++ b/src/hooks/useWatermark.ts @@ -69,16 +69,19 @@ export function useWatermark(parentEl: Ref = bodyEl) { /** 创建水印元素 */ const createWatermarkEl = () => { + const isBody = parentEl.value!.tagName.toLowerCase() === bodyEl.value.tagName.toLowerCase() + const watermarkElPosition = isBody ? "fixed" : "absolute" + const parentElPosition = isBody ? "" : "relative" watermarkEl = document.createElement("div") watermarkEl.style.pointerEvents = "none" watermarkEl.style.top = "0" watermarkEl.style.left = "0" - watermarkEl.style.position = "absolute" + watermarkEl.style.position = watermarkElPosition watermarkEl.style.zIndex = "99999" const { clientWidth, clientHeight } = parentEl.value! updateWatermarkEl({ width: clientWidth, height: clientHeight }) // 设置水印容器为相对定位 - parentEl.value!.style.position = "relative" + parentEl.value!.style.position = parentElPosition // 将水印元素添加到水印容器中 parentEl.value!.appendChild(watermarkEl) } diff --git a/src/styles/index.scss b/src/styles/index.scss index b03d7ca..3df79fe 100644 --- a/src/styles/index.scss +++ b/src/styles/index.scss @@ -27,7 +27,7 @@ body { -webkit-font-smoothing: antialiased; font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", Arial, sans-serif; - @include scrollbar(); + @include scrollbar; } #app {