html2canvas的使用
- 引入 html2canvas.js
htmlcanvas(){
html2canvas(document.getElementById('share'), {
useCORS: true,//跨域
scale:3,//放大
dpi:window.devicePixelRatio * 4,//清晰度
width: $('.share').width(),//宽
height: $('.share').height(),//高
backgroundColor: null,
}).then(function (canvas) {//回调
var imgUrl = canvas.toDataURL('image/jpeg') //jpeg 会生成 jpg图片,png 则生成 png图片,png图片会很大 加载很慢,建议还是生成jpg的
document.getElementById('shareImg').src= imgUrl;
})
}