当前位置: 首页 > 知识库问答 >
问题:

前端 - 视频播放器DPlayer全屏水印不显示?

栾和风
2023-05-24

在h5中用视频播放器DPlayer
监听竖屏和横屏(webfullscreen、fullscreen),更改水印范围,在竖屏的时候没问题,在横屏的时候看不到水印


/** 水印添加方法  */
 
let setWatermark = (str1, str2, container) => {
  let id = '1.23452384164.123412415';
  if (container === undefined) {
    return;
  }
  if (document.getElementById(id) !== null) {
    document.body.removeChild(document.getElementById(id));
  }
  // 设置局部水印
  var containerWidth = container.offsetWidth; // 获取父容器宽
  var containerHeight = container.offsetHeight; // 获取父容器高
  container.style.position = 'relative'; // 设置布局为相对布局
  var top = Math.random() * (containerHeight - 92);
  var left = Math.random() * (containerWidth - 548);
  let can = document.createElement('canvas');
  // 设置canvas画布大小
  can.width = 294;
  // can.width = 334;
  can.height = 90;
 
  let cans = can.getContext('2d');
  cans.rotate((-20 * Math.PI) / 180); // 水印旋转角度
  cans.font = '15px Vedana';
  // cans.font = '20px Vedana';
  cans.fillStyle = '#FFFF00  ';
  // cans.fillStyle = '#AAAAAA';
  // cans.textAlign = 'center';
  cans.border = '1px solid red';
  cans.textBaseline = 'Middle';
  cans.fillText(str1, can.width / 2, can.height); // 水印在画布的位置x,y轴
  cans.fillText(str2, can.width / 2, can.height + 22);
 
  let div = document.createElement('div');
  div.id = id;
  div.style.pointerEvents = 'none';
  div.style.top = top + 'px';
  div.style.left = left + 'px';
  div.style.opacity = '0.15';
  div.style.position = 'fixed';
  div.style.zIndex = '400000';
  div.style.width = '294px';
  // div.style.width = '394px';
  div.style.height = '90px';
  div.style.background = 'url(' + can.toDataURL('image/png') + ') left top repeat';
  // document.body.appendChild(div);
  container.appendChild(div);
console.log('container', container);
 
 
  return id;
};
 
// 添加水印方法
export const setWaterMark = (str1, str2, container) => {
  let id = setWatermark(str1, str2, container);
  if (document.getElementById(id) === null) {
    id = setWatermark(str1, str2, container, isfullscreen);
  }
};
 
// 移除水印方法
export const removeWatermark = () => {
  let id = '1.23452384164.123412415';
  if (document.getElementById(id) !== null) {
    document.body.removeChild(document.getElementById(id));
  }
};

共有1个答案

周鸿云
2023-05-24

这是官方文档看看操作对吗:https://dplayer.diygod.dev/zh/guide.html

 类似资料: