当前位置:网站首页>Use canvas to add text watermark to the page
Use canvas to add text watermark to the page
2022-06-11 18:50:00 【Summer】
Reference resources :
vue Add watermark to the page - Simple books
Code : I made some changes according to our needs
let watermark = {};
let setWatermark = (str, targetDom) => {
let id = 'watermark';
if (document.getElementById(id) !== null) {
document.body.removeChild(document.getElementById(id));
}
let can = document.createElement("canvas");
can.width = 200;
can.height = 100;
let cans = can.getContext("2d");
cans.rotate((-20 * Math.PI) / 180);
cans.font = "15px Vedana";
cans.fillStyle = "rgba(0, 0, 0, 0.30)";
cans.textAlign = "left";
cans.textBaseline = "Middle";
cans.fillText(str, can.width / 20, can.height);
let div = document.createElement("div");
div.id = id;
div.style.pointerEvents = "none";
div.style.top = targetDom.offsetTop + "px";
div.style.left = targetDom.offsetLeft + "px";
div.style.position = "fixed";
div.style.zIndex = "100000";
div.style.width = targetDom.clientWidth + "px";
div.style.height = targetDom.clientHeight + "px";
div.style.background =
"url(" + can.toDataURL("image/png") + ") left top repeat";
document.body.appendChild(div);
return id;
};
// If the watermark exists Show watermark If it doesn't exist Show after creation
// targetDom Is the element to be covered by the watermark
watermark.set = (str, targetDom) => {
if (document.getElementById('watermark')) {
document.getElementById('watermark').style.display = 'block'
} else {
let id = setWatermark(str, targetDom);
let timer = setInterval(() => {
if (document.getElementById(id) === null) {
id = setWatermark(str, targetDom);
} else {
clearInterval(timer)
}
}, 2000);
window.onresize = () => {
setWatermark(str, targetDom);
};
}
};
// Show watermarks when switching pages Because the project component is keep-alive Of So in beforeRouteEnter Adjust this when
watermark.show = () => {
if (document.getElementById('watermark')) {
document.getElementById('watermark').style.display = 'block'
}
}
//beforeRouteLeave You may need to hide the watermark when switching other pages
watermark.hide = () => {
document.getElementById('watermark').style.display = 'none'
}
export default watermark边栏推荐
- Let our tanks move happily
- SAP BTP 上 workflow 和 Business Service 的 project 管理
- 牛客刷题——两种排序方法
- User group actions
- * Jetpack 笔记 使用DataBinding
- Introduction to basic use and pit closure of BigDecimal
- Niu Ke brushes the question - no two
- 牛客刷题——part6
- 己方坦克发射子弹
- Force deduction 33 questions, search rotation sorting array
猜你喜欢

更换目标检测的backbone(以Faster RCNN为例)

Swagger2简单使用

非递归实现二叉树的前、中、后序遍历
Uploading and downloading of necessary files in development

WWDC22 开发者需要关注的重点内容

Monitoring loss functions using visdom

Visual slam lecture notes-10-1

Why is ti's GPMC parallel port more often used to connect FPGA and ADC? I give three reasons

全志T3开发板(4核ARM Cortex-A7)——系统启动阶段LOGO显示详解

MBA, EMBA, MPa, MEM, pre interview (pre interview) time batch of national colleges and universities has been released (continuously updated) - Wendu Management Institute
随机推荐
制造出静态坦克
cf:D. Black and White Stripe【连续k个中最少的个数 + 滑动窗口】
全志T3开发板(4核ARM Cortex-A7)——系统启动阶段LOGO显示详解
7-3 组合问题(*)
Surveillance des fonctions de perte avec visdom
Realize that you can continue to play
力扣刷题——二叉树的最近公共祖先
牛客刷题——part8
5 minutes to understand the red, blue and purple in the attack and defense drill
Learn to use LSTM and IMDB comment data for emotion analysis training
KMP!你值得拥有!!! 直接运行直接跑!
使用图像处理技术和卷积神经网络(CNN)的作物病害检测
leetcode:926. Flip the string to monotonically increasing [prefix and + analog analysis]
SQL注入漏洞学习之一:phpstudy集成环境搭建DVWA靶场
V-for loop traversal
防止敌方坦克重叠
对‘g2o::VertexSE3::VertexSE3()’未定义的引用
* Jetpack 笔记 LifeCycle ViewModel 与LiveData的了解
On the sequence traversal of binary tree Ⅱ
Tips for using apipost