加水印的需求都是为了不可去除的。所以一定要防止用户通过打开控制台, 进行css操作,再截图。
用到的 api 是window.MutationObserver 。
话不多说, 上代码:
思路就是:当你监控到某一个元素样式变化了,你就再给style 画上。
const canvasWM = ({
container = document.body,
width = '160px',
height = '130px',
textAlign = 'center',
font = '15px Microsoft Yahei',
fillStyle = 'rgba(184, 184, 184, 0.6)',
content = '请勿外传',
rotate = '30',
zIndex = 1000,
} = {
}) => {
// eslint-disable-next-line no-undef
const [args] = arguments;
const canvas = document.createElement(