2015-01-16 24 views
1

我想一个html字符串转换为类似的图像,以它是如何在这里完成: html2canvas creates a canvas with a width and height of zero?渲染HTML字符串,但不显示HTML本身以帆布

不过我不想表现出比对结果图像的任何其他这一页。因此,我不能简单地将html字符串添加到DOM中,就像在那里建议的那样。我想我想要实现的是可能的,因为html2canvas test console就是这样做的。

我试图产生空的结果如下:

var doc = document.implementation.createHTMLDocument(); 
 
doc.open(); 
 
doc.write("<html><header></header><body><div>test</div></body></html>"); 
 
doc.close(); 
 

 
html2canvas(doc.body, { 
 
    onrendered:function(newCanvas) { 
 
     document.body.appendChild(newCanvas); 
 
    }  
 
});
<script src="https://github.com/niklasvh/html2canvas/blob/master/dist/html2canvas.js"></script>

任何人都可以提出这样做​​的方式是什么?

回答

0

我想通了。这是the link让我走向正确的方向。查看说明这个想法的this page的源代码也是值得的。

我们设置了容器

style="overflow:hidden" 

属性和移动,我们要渲染的视口的外侧

style="position:absolute;top:0px;left:3000px;" 

希望帮助别人的内容。