如何使用onclick()将div捕获为图像并本地保存?

时间:2019-12-23 10:26:10

标签: javascript html2canvas

我很难捕获具有多个图像的div作为图像并将其保存为默认名称的本地文件夹。有人可以帮我吗?

Js Code

$(document).ready(function() {
   $("#btn-one").click(function(){
//var testdiv = document.getElementById("testdiv");
    html2canvas($("#rocket-image"), {
        onrendered: function(canvas) {
            // canvas is the final rendered <canvas> element
            var myImage = canvas.toDataURL("image/png");
            window.open(myImage);
        }
    });
});
});

HTML code
<div id="rocket-image" class="rocket-holder"> 
<img id="mainDeckel" src="images/image-1.png" alt="" > 
<img id="mainKorper" src="images/image.png" alt="" >
<img id="mainAccess" src="images/image.png" alt="" >
img id="mainDusen" src="images/image.png" alt="" > 
 </div>
<a id="btn-one" href="" class="btn-one">Capture</a id=""> </div>

0 个答案:

没有答案