Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the watermarking effect with vue

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how vue achieves the effect of watermarking. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Foreword:

Watermark effect is used in vue project. You can specify a 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 = 150can.height = can.getContext (' 2d') cans.rotate (- 20 * Math.PI / cans) 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 allows only one call Secondary * @ param: * @ text = = watermark content * @ sourceBody = = where is the watermark added 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. Configure globally in main.js

/ / Watermark import watermark from'. / utils/watermark.js'Vue.prototype.$watermark = watermark

3. Use-full screen watermark in the page

This.$watermark.set ("Haoxing 2731")

4. Use in the page-specify a container

Click on me to add watermark 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 = 150can.height = 120Thank you for your reading! This is the end of this article on "how to achieve watermarking effect in vue". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report