简体   繁体   English

使用html2canvas创建图像而不是截图

[英]Create image more than screenshot with html2canvas

I have this code 我有这个代码

html2canvas($(".container"), {imageTimeout: 2000, removeContainer: true}).then(function(canvas) {
   img = canvas.toDataURL("image/png"),
   doc = new jsPDF({
     unit: 'px',
     format: 'a4'
   });
    window.open(img);
});

I would like that all HTML in $(".container") appeared in my image, but it only creates image with HTML that appeared in screen.. 我希望$(“。container”)中的所有HTML都出现在我的图像中,但是它只创建带有出现在屏幕中的HTML的图像。

What i understand i write this code. 我的理解是我写这段代码。 Hope this code help you. 希望这段代码对您有所帮助。

html2canvas($("#container"), {
 onrendered: function (canvas) {
         var imgData = canvas.toDataURL('image/png');
         var a = document.createElement('a');
         a.href = imgData ;
         a.download = 'somefilename.png';
         a.click();
 }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM