[英]html2canvas is not reading inline background-color style
我正在使用html2canvas,除了使用div样式时不读取div的背景颜色外,它的效果都很好。 但是,当使用样式表时它确实可以工作,但是由于颜色是由react控制的,因此我需要它以读取内联样式为佳,有人可以帮助解决此问题吗?
我的html:
<div id="testDiv" class="page" style="width: 530px; height: 630px; background-color: red; position: relative;">...</div>
我的js:
function getThumbnail = (div) => {
return html2canvas(div).then(canvas => {
return canvas.toDataURL();
});
}
除非添加以下内容,否则上述代码中的图像将无背景渲染:
#testDiv {
background-color: red;
}
在样式表中,但是要设置背景变量并不容易。
更新:我也尝试过使用css变量,但是html2canvas也没有采用这种样式。
:root {
--garment-colour: #000000;
};
#testDiv {
background-color: var(--garment-colour);
}
它确实显示了背景。 有关图像数据,请参见控制台日志。
html2canvas(document.querySelector("#testDiv")).then(canvas => {
console.log(canvas.toDataURL());
});
这是小提琴: https : //jsfiddle.net/nxrvsphz/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.