优化:解决部分场景下, 页面元素变化导致水印覆盖不全问题

This commit is contained in:
陈精华 2025-03-31 15:28:36 +08:00
parent 2230cfa52b
commit 874ff5b3f6
No known key found for this signature in database
GPG Key ID: 30BDC970902B755D

View File

@ -8,7 +8,19 @@
*/ */
function initWaterMark() { function initWaterMark() {
let watermarkTxt = '${watermarkTxt}'; let watermarkTxt = '${watermarkTxt}';
if (watermarkTxt !== '') { if (watermarkTxt === '') {
return;
}
let lastWidth = 0;
let lastHeight = 0;
const checkResize = () => {
const currentWidth = document.documentElement.scrollWidth;
const currentHeight = document.documentElement.scrollHeight;
// 检测尺寸是否变化
if (currentWidth === lastWidth && currentHeight === lastHeight) {
return;
}
// 如果变化了, 重新初始化水印
watermark.init({ watermark.init({
watermark_txt: '${watermarkTxt}', watermark_txt: '${watermarkTxt}',
watermark_x: 0, watermark_x: 0,
@ -25,7 +37,11 @@
watermark_height: ${watermarkHeight}, watermark_height: ${watermarkHeight},
watermark_angle: ${watermarkAngle}, watermark_angle: ${watermarkAngle},
}); });
} // 更新存储的宽口大小
lastWidth = currentWidth;
lastHeight = currentHeight;
};
setInterval(checkResize, 1000);
} }
</script> </script>