页面有100个宽度为200px的正方形横着平铺,正方形里面有文字和颜色,转为canvas 元素后,在左侧会出现黑色的几个正方形,当删除几个后就好了,为啥啊,会不会和电脑性能有关系,求解答一下
(1)使用 backgroundColor 这个属性可以设置 canvas 的背景色:
默认值为白色(#ffffff)
如果想要背景透明,可以将其设为 null
(2)下面将背景色改成绿色
原文:JS - 使用 html2canvas 将页面保存成图片(或对指定元素截图)
html2canvas(document.querySelector("#capture"),{
width: 240,
height: 120,
backgroundColor: "#00ff00"
}).then(canvas => {
document.body.appendChild(canvas)
});