给项目添加水印

1. 新建WaterMark.js文件

class WaterMark {
  static set (str) {
    const id = '1.23452384164.123412415'

    const oldNode = document.getElementById(id)
    if (oldNode) {
      document.body.removeChild(oldNode)
    }

    const can = document.createElement('canvas')
    can.width = 150
    can.height = 120

    const ctx = can.getContext('2d')
    if (ctx) {
      ctx.rotate((-20 * Math.PI) / 180)
      ctx.font = '20px Vedana'
      ctx.fillStyle = 'rgba(200, 200, 200, 0.20)'
      ctx.textAlign = 'left'
      ctx.textBaseline = 'middle'
      ctx.fillText(str, can.width / 4, can.height / 2)
    }

    const div = document.createElement('div')
    div.id = id
    div.style.pointerEvents = 'none'
    div.style.top = '64px'  //调用覆盖范围
    div.style.left = '100px'
    div.style.position = 'fixed'
    div.style.zIndex = '100000'
    div.style.width = '100%'
    div.style.height = '100vh'
    div.style.background = `url(${can.toDataURL('image/png')}) left top repeat`
    document.body.appendChild(div)
  }
}

export default WaterMark

2. 使用

  在需要使用的js文件中引入WaterMark.js,用户登陆成功之后调用 WaterMark(userId)

转载于:https://www.cnblogs.com/ihuangqing/p/11469579.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值