Vue uses custom instructions to add watermarks to the bottom of the page

Vue uses custom instructions to add watermarks to the bottom of the page

Project Scenario

Add a custom watermark to the entire background of the project. You can change the watermark text, font color, etc.

Implementation ideas

  • The technology used here is mainly canvas. In the process of realizing watermarking, the characteristics of canvas are mainly used.
  • Use the canvas feature to generate a base64 image file, and then set its font size, color, etc.
  • Finally, set it as the background image, which realizes the watermark effect of the page

Achieve results

Implementation Code

<template>
  <div class="water-marker" >
      <div v-waterMarker="{text:'Carlo vest - All rights reserved',textColor:'rgba(180, 180, 180, 0.4)'}">
        <div class="water-marker-item">Testing problem, testing problem, testing problem, testing problem, testing problem, testing problem</div>
      </div>
  </div>
</template>

<script>
import waterMarker from '../../directive/test/waterMarker'
export default {
  directives: {
    waterMarker
  },
  data(){
    return {
    }
  },
  methods:{
  }
}
</script>

<style lang="scss">
.water-marker{
  height: 300px;
  .water-marker-item{
    line-height: 300px;
  }
}
</style>

The waterMarker.js file is as follows:

function addWaterMarker(str, parentNode, font, textColor) {
  // Watermark text, parent element, font, text color var can = document.createElement('canvas')
  parentNode.appendChild(can)
  can.width = 200
  can.height = 150
  can.style.display = 'none'
  var cans = can.getContext('2d')
  cans.rotate((-20 * Math.PI) / 180)
  cans.font = font || '16px Microsoft JhengHei'
  cans.fillStyle = textColor || 'rgba(180, 180, 180, 0.3)'
  cans.textAlign = 'left'
  cans.textBaseline = 'Middle'
  cans.fillText(str, can.width / 10, can.height / 2)
  parentNode.style.backgroundImage = 'url(' + can.toDataURL('image/png') + ')'
}

const waterMarker = {
  bind: function (el, binding) {
    addWaterMarker(binding.value.text, el, binding.value.font, binding.value.textColor)
  },
}

export default waterMarker

This is the end of this article about how to use custom instructions in Vue to add a watermark at the bottom of the page. For more relevant content about adding a watermark at the bottom of the Vue page, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • The vue project realizes drawing a watermark in a certain area
  • Vue easily realizes watermark effect
  • Vue's global watermark implementation example
  • Vue integrates PDF.js to implement PDF preview and add watermark steps
  • Vue example code using class to create and clear watermark
  • How to use pictures and picture watermarks with hidden text information in Vue
  • Vue implements page watermark function
  • Vue implements adding watermark effect to the page

<<:  Example of using CASE WHEN in MySQL sorting

>>:  VSCode+CMake+Clang+GCC environment construction tutorial under win10

Recommend

What is flex and a detailed tutorial on flex layout syntax

Flex Layout Flex is the abbreviation of Flexible ...

Detailed explanation of using MySQL where

Table of contents 1. Introduction 2. Main text 2....

React Fiber structure creation steps

Table of contents React Fiber Creation 1. Before ...

In-depth understanding of MySQL self-connection and join association

1. MySQL self-connection MySQL sometimes needs to...

How to query duplicate data in mysql table

INSERT INTO hk_test(username, passwd) VALUES (...

Various ways to achieve the hollowing effect of CSS3 mask layer

This article introduces 4 methods to achieve mask...

Five solutions to cross-browser problems (summary)

Brief review: Browser compatibility issues are of...

Key features of InnoDB - insert cache, write twice, adaptive hash index details

The key features of the InnoDB storage engine inc...

Detailed explanation of MySQL 8.0.18 commands

Open the folder C:\web\mysql-8.0.11 that you just...

How to install and configure MySQL and change the root password

1. Installation apt-get install mysql-server requ...

Nginx service 500: Internal Server Error one of the reasons

500 (Internal Server Error) The server encountere...