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
Preface: After studying the previous article, we ...
Official documentation: JSON Functions Name Descr...
Using the CSS float property correctly can become...
1|0MySQL (MariaDB) 1|11. Description MariaDB data...
In the MySQL database, when we need fuzzy query, ...
This article shares the specific code of Vue to i...
HTML comments, we often need to make some HTML co...
Recently, when I was working on monitoring equipm...
This article shares with you how to use canvas an...
According to null-values, the value of null in My...
Preface PC Server has developed to this day and h...
What is serdel userdel is a low-level tool for de...
Effect screenshots: Implementation code: Copy code...
Stored Procedures 1. Create a stored procedure an...
1. flex-grow, flex-shrink, flex-basis properties ...