html - 使用 HTML2Canvas 将大于屏幕的 DIV 渲染为图像

标签 html html2canvas

我正在使用 HTML2Canvas 将 DIV 转换为 PNG。一切进展顺利,但是当我的 DIV 大于屏幕时,只有屏幕中 DIV 的可见部分才会呈现在图像中。

是否有任何解决方法可以将整个 DIV 渲染到图像中?

这是我的代码:

html2canvas(divDrop, {
    onrendered: function (canvas) {
        imgMap.style.display = "";
        imgMap.src = canvas.toDataURL("image/png");
    },
    width: divDrop.clientWidth,
    height: divDrop.clientHeight
});

最佳答案

正如评论中所述,我发布了以下工作链接:

<强> JSFiddle example

$(function() { 
    $("#btnSave").click(function() { 
        html2canvas($("#widget"), {
            onrendered: function(canvas) {
                theCanvas = canvas;
                document.body.appendChild(canvas);

                // Convert and download as image 
                Canvas2Image.saveAsPNG(canvas); 
                $("#img-out").append(canvas);
                // Clean up 
                //document.body.removeChild(canvas);
            }
        });
    });
}); 

关于html - 使用 HTML2Canvas 将大于屏幕的 DIV 渲染为图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32984870/

相关文章:

html - 调整图像大小以适合屏幕

html - @font-face - 为一种字体使用多个文件

javascript - ionic 4 html2canvas

html - 如何防止 CSS3 转换反向?

html - 检查 HTML 中的变量类型

javascript - 为什么 html2canvas 为 MS Edge 上的表格捕获比 Chrome 更小的字节数组 Canvas

javascript - 对象不是函数,在 jspdf 调用中

image - html2canvas和jsPDF部分灰色部分

javascript - "onrendered"在javascript中是如何使用的?

javascript - 聊天应用程序的自下而上布局设计