当前位置:   article > 正文

前端实现页面水印

前端实现页面水印
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. * {
  9. box-sizing: border-box;
  10. list-style: none;
  11. }
  12. html {
  13. margin: 0;
  14. padding: 0;
  15. }
  16. body {
  17. margin: 0 !important;
  18. padding: 0;
  19. height: auto;
  20. }
  21. .box {
  22. width: 100%;
  23. height: 100vh;
  24. overflow: scroll;
  25. border: 1px solid red;
  26. }
  27. /* 滚动条样式 */
  28. .box::-webkit-scrollbar {
  29. width: 10px;
  30. background: #fff;
  31. }
  32. .box::-webkit-scrollbar-thumb {
  33. border-radius: 3px;
  34. height: 100px;
  35. background-color: #d5dde8;
  36. margin-left: 6px;
  37. }
  38. </style>
  39. </head>
  40. <body>
  41. <div class="box">
  42. <p>123421</p>
  43. <p>123421</p>
  44. <p>123421</p>
  45. <p>123421</p>
  46. <p>123421</p>
  47. <p>123421</p>
  48. <p>123421</p>
  49. <p>123421</p>
  50. <p>123421</p>
  51. </div>
  52. <script>
  53. function addWaterMarker(str, name, number) {
  54. let can = document.createElement('canvas');
  55. let body = document.body;
  56. body.appendChild(can);
  57. can.width = 180;
  58. can.height = 150;
  59. can.style.display = 'none';
  60. let cans = can.getContext('2d');
  61. cans.rotate(-20 * Math.PI / 180);
  62. cans.font = "normal 12px Microsoft JhengHei";
  63. cans.fillStyle = "rgba(223, 223, 223, 1)";
  64. cans.textAlign = 'center';
  65. cans.textBaseline = 'Middle';
  66. let nameNo = name + ' ' + str;
  67. cans.fillText(nameNo, can.width / 3, can.height / 2);
  68. cans.fillText(number, can.width / 2.7, can.height / 1.6);
  69. let dom = document.querySelector('.box')
  70. dom.style.backgroundImage = `url(${can.toDataURL("image/png" + '')})`;
  71. dom.style.backgroundColor = "#fff";
  72. }
  73. addWaterMarker('张三', 'Code12345', 1888888888)
  74. </script>
  75. </body>
  76. </html>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/159174
推荐阅读
相关标签
  

闽ICP备14008679号