直播数据中心

ceshi1.html 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
  6. </head>
  7. <body>
  8. <div>
  9. <h6>测试页面 测试页面</h6>
  10. <h5>测试页面 测试页面</h5>
  11. <h4>测试页面 测试页面</h4>
  12. <h3>测试页面 测试页面</h3>
  13. <h2>测试页面 测试页面</h2>
  14. <h1>测试页面 测试页面</h1>
  15. </div>
  16. </body>
  17. <script src="shuiyin.js"></script>
  18. <script type="text/javascript">
  19. var now = getNow();
  20. watermark({"watermark_txt":"A B C X Y Z "+now});
  21. function watermark(settings) {
  22. //默认设置
  23. var defaultSettings = {
  24. watermark_txt: "text",
  25. watermark_x: 20, //水印起始位置x轴坐标
  26. watermark_y: 20, //水印起始位置Y轴坐标
  27. watermark_rows: 20, //水印行数
  28. watermark_cols: 20, //水印列数
  29. watermark_x_space: 100, //水印x轴间隔
  30. watermark_y_space: 50, //水印y轴间隔
  31. watermark_color: '#aaa', //水印字体颜色
  32. watermark_alpha: 0.4, //水印透明度
  33. watermark_fontsize: '15px', //水印字体大小
  34. watermark_font: '微软雅黑', //水印字体
  35. watermark_width: 210, //水印宽度
  36. watermark_height: 80, //水印长度
  37. watermark_angle: 20 //水印倾斜度数
  38. };
  39. if (arguments.length === 1 && typeof arguments[0] === "object") {
  40. var src = arguments[0] || {};
  41. for (key in src) {
  42. if (src[key] && defaultSettings[key] && src[key] === defaultSettings[key]) continue;
  43. else if (src[key]) defaultSettings[key] = src[key];
  44. }
  45. }
  46. var oTemp = document.createDocumentFragment();
  47. //获取页面最大宽度
  48. var page_width = Math.max(document.body.scrollWidth, document.body.clientWidth);
  49. var cutWidth = page_width * 0.0150;
  50. var page_width = page_width - cutWidth;
  51. //获取页面最大高度
  52. var page_height = Math.max(document.body.scrollHeight, document.body.clientHeight) + 450;
  53. page_height = Math.max(page_height, window.innerHeight - 30);
  54. //如果将水印列数设置为0,或水印列数设置过大,超过页面最大宽度,则重新计算水印列数和水印x轴间隔
  55. if (defaultSettings.watermark_cols == 0 || (parseInt(defaultSettings.watermark_x + defaultSettings.watermark_width * defaultSettings.watermark_cols + defaultSettings.watermark_x_space * (defaultSettings.watermark_cols - 1)) > page_width)) {
  56. defaultSettings.watermark_cols = parseInt((page_width - defaultSettings.watermark_x + defaultSettings.watermark_x_space) / (defaultSettings.watermark_width + defaultSettings.watermark_x_space));
  57. defaultSettings.watermark_x_space = parseInt((page_width - defaultSettings.watermark_x - defaultSettings.watermark_width * defaultSettings.watermark_cols) / (defaultSettings.watermark_cols - 1));
  58. }
  59. //如果将水印行数设置为0,或水印行数设置过大,超过页面最大长度,则重新计算水印行数和水印y轴间隔
  60. if (defaultSettings.watermark_rows == 0 || (parseInt(defaultSettings.watermark_y + defaultSettings.watermark_height * defaultSettings.watermark_rows + defaultSettings.watermark_y_space * (defaultSettings.watermark_rows - 1)) > page_height)) {
  61. defaultSettings.watermark_rows = parseInt((defaultSettings.watermark_y_space + page_height - defaultSettings.watermark_y) / (defaultSettings.watermark_height + defaultSettings.watermark_y_space));
  62. defaultSettings.watermark_y_space = parseInt(((page_height - defaultSettings.watermark_y) - defaultSettings.watermark_height * defaultSettings.watermark_rows) / (defaultSettings.watermark_rows - 1));
  63. }
  64. var x;
  65. var y;
  66. for (var i = 0; i < defaultSettings.watermark_rows; i++) {
  67. y = defaultSettings.watermark_y + (defaultSettings.watermark_y_space + defaultSettings.watermark_height) * i;
  68. for (var j = 0; j < defaultSettings.watermark_cols; j++) {
  69. x = defaultSettings.watermark_x + (defaultSettings.watermark_width + defaultSettings.watermark_x_space) * j;
  70. var mask_div = document.createElement('div');
  71. mask_div.id = 'mask_div' + i + j;
  72. mask_div.className = 'mask_div';
  73. mask_div.appendChild(document.createTextNode(defaultSettings.watermark_txt));
  74. //设置水印div倾斜显示
  75. mask_div.style.webkitTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
  76. mask_div.style.MozTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
  77. mask_div.style.msTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
  78. mask_div.style.OTransform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
  79. mask_div.style.transform = "rotate(-" + defaultSettings.watermark_angle + "deg)";
  80. mask_div.style.visibility = "";
  81. mask_div.style.position = "absolute";
  82. mask_div.style.left = x + 'px';
  83. mask_div.style.top = y + 'px';
  84. mask_div.style.overflow = "hidden";
  85. mask_div.style.zIndex = "9999";
  86. //让水印不遮挡页面的点击事件
  87. mask_div.style.pointerEvents = 'none';
  88. mask_div.style.opacity = defaultSettings.watermark_alpha;
  89. mask_div.style.fontSize = defaultSettings.watermark_fontsize;
  90. mask_div.style.fontFamily = defaultSettings.watermark_font;
  91. mask_div.style.color = defaultSettings.watermark_color;
  92. mask_div.style.textAlign = "center";
  93. mask_div.style.width = defaultSettings.watermark_width + 'px';
  94. mask_div.style.height = defaultSettings.watermark_height + 'px';
  95. mask_div.style.display = "block";
  96. oTemp.appendChild(mask_div);
  97. };
  98. };
  99. document.body.appendChild(oTemp);
  100. }
  101. function getNow() {
  102. var d = new Date();
  103. var year = d.getFullYear();
  104. var month = change(d.getMonth() + 1);
  105. var day = change(d.getDate());
  106. var hour = change(d.getHours());
  107. var minute = change(d.getMinutes());
  108. var second = change(d.getSeconds());
  109. function change(t) {
  110. if (t < 10) {
  111. return "0" + t;
  112. } else {
  113. return t;
  114. }
  115. }
  116. var time = year + '年' + month + '月' + day + '日 ' + hour + '时' + minute + '分' + second + '秒';
  117. return time;
  118. }
  119. </script>
  120. </html>