html5canvas

html2canvas

let node = document.getElementById(myId);
let width = node.offsetWidth;
let height = node.offsetHeight;
let scale = 1; //倍数
html2canvas(node, {
  width: width,
  heigth: height,
  backgroundColor: '#ffffff',
  dpi: window.devicePixelRatio * 3,
  scale: scale,
  X: 0,
  Y: 0,
  scrollX: 10,
  scrollY: 0,
  useCORS: true, //这个不设置会导致部分dom无法下载
  allowTaint: true
}).then(canvas => {
  let url = canvas.toDataURL();
  let a = document.createElement('a');
  a.download = '这是下载昵称';
  let event = new MouseEvent('click');
  a.href = url;
  a.dispatchEvent(event);
});
上次更新: