如何使用 HTM5 画布将 DIV 另存为图像?
htmljavascriptprogramming scripts
借助 JavaScript 中的 html2canvas() 函数,可以将 DIV 内容另存为图像。DIV 标签定义 HTML 文档中的部分。
示例
<div id = ”cpimg” style = ”padding: 25px ; ” > <h4>欢迎</h4> </div>
这显示了名为 cpimg的分区。
html2canvas() 函数使用以下代码 − 将 div 保存为图像
html2canvas(document.querySelector(“#cpimg”)).then(canvas { document.body.appendChild(canvas) });
它将引用的 div 部分 “cpimg” 保存到图像中。