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 {