Preface:Use watermark effect in vue project, you can specify the container Effect picture:1. Do not specify a container 2. Specify the container Implementation method:1. Create a new configuration file watermark.js, which can be placed in util or somewhere else let watermark = {} let setWatermark = (text, sourceBody) => { let id = Math.random()*10000+'-'+Math.random()*10000+'/'+Math.random()*10000 if (document.getElementById(id) !== null) { document.body.removeChild(document.getElementById(id)) } let can = document.createElement('canvas') can.width = 150 can.height = 120 let cans = can.getContext('2d') cans.rotate(-20 * Math.PI / 180) cans.font = '15px Vedana' cans.fillStyle = 'rgba(0, 0, 0, .5)' cans.textAlign = 'left' cans.textBaseline = 'Middle' cans.fillText(text, can.width / 20, can.height ) let water_div = document.createElement('div') water_div.id = id water_div.style.pointerEvents = 'none' water_div.style.background = 'url(' + can.toDataURL('image/png') + ') left top repeat' if(sourceBody){ water_div.style.width = '100%' water_div.style.height = '100%' sourceBody.appendChild(water_div) }else{ water_div.style.top = '3px' water_div.style.left = '0px' water_div.style.position = 'fixed' water_div.style.zIndex = '100000' water_div.style.width = document.documentElement.clientWidth + 'px' water_div.style.height = document.documentElement.clientHeight + 'px' document.body.appendChild(water_div) } return id } /** * This method can only be called once * @param: * @text == watermark content * @sourceBody == where the watermark is added, if not passed, it is body * */ watermark.set = (text, sourceBody) => { let id = setWatermark(text, sourceBody) setInterval(() => { if (document.getElementById(id) === null) { id = setWatermark(text, sourceBody) } }, 2000) window.onresize = () => { setWatermark(text, sourceBody) } } export default watermark 2. Global configuration in main.js // Watermarkimport watermark from './utils/watermark.js' Vue.prototype.$watermark = watermark 3. Use full screen watermark in the page this.$watermark.set("Haoxing 2731") 4. Use-specified container in the page <el-button @click="addWatermark">Click me to add watermark</el-button> <div ref="content" style="width: 500px;height: 500px;border: 1px solid #ccc;"> addWatermark(){ this.$watermark.set("Haoxing 2731",this.$refs.content) } 5. If you think the distance between fonts is too large, just change this property can.width = 150 can.height = 120 The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: MySQL Database Basics: A Summary of Basic Commands
>>: Summary of 10 common HBase operation and maintenance tools
Table of contents 1. Front-end leading process: 2...
HTML text formatting tags 標簽 描述 <b> 定義粗體文本 ...
According to the coefficient of pi and the radius...
Prelude We all know that nginx is an excellent re...
This article is based on the Free Code Camp Basic...
This article is mainly to take you to quickly und...
You may have set a MySQL password just now, but f...
Table of contents 1. prototype (explicit prototyp...
As one of the most commonly used and important ut...
What is NFS? network file system A method or mech...
Table of contents 1. Event delegation Event Bubbl...
Table of contents 1. Initialize the map 2. Map Po...
In relational databases, pessimistic locking and ...
1. Preliminary preparation (windows7+mysql-8.0.18...
illustrate: There are two main types of nginx log...