html2canvas合成图片的时候,dom中的一些图片出不来,而且是偶现的,页面没有报错

新手上路,请多包涵

html2canvas合成图片的时候,dom中的一些图片出不来,而且是偶现的,页面没有报错。
import html2canvas from 'html2canvas';
export default function convert2canvas(selector) {
const shareContent = document.querySelector(selector);
const width = shareContent.offsetWidth;
const height = shareContent.offsetHeight;
const canvas = document.createElement('canvas');
const scale = 2;
canvas.width = width * scale;
canvas.height = height * scale;
canvas.getContext('2d').scale(scale, scale);
const opts = {

scale: scale,
canvas: canvas,
taintTest: false,
useCORS: true,
allowTaint: false,
logging: true,
width: width,
height: height

};
html2canvas(shareContent, opts).then(function(canvas) {

const img = new Image();
const url = canvas.toDataURL();
img.src = url;
img.onload = function() {
  top.postMessage(url, '*');
};
img.style.position = 'fixed';
img.style.top = '0';
img.style.bottom = '0';
img.style.left = '0';
img.style.right = '0';
img.style.width = '100%';
img.style.height = '100%';
img.setAttribute('id', 'poster');
const previousImg = document.getElementById('poster');
if (previousImg) {
  console.info(1);
  document.body.replaceChild(img, previousImg);
  return;
}
document.body.appendChild(img);

});
}

阅读 2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题