-
前言
这两天有个需求,需要保存页面的dom元素为图片到本地,之前没有做过类似的效果,通过github搜索了一下,找到两个github库,
一个为domtoimage:https://github.com/tsayen/dom-to-image; star:3539;
另一个为htmltocanvas:https://github.com/niklasvh/html2canvas/, star12073;
两个都试用后,最后选择了第二个.
使用方法
使用方法很简单:在正常的html中引入html2canvas.js后只需要写如下几行代码;
html2canvas(document.getElementById("container")) .then(function (canvas) { document.body.appendChild(canvas) })
遇到的问题
在使用文本渐变功能的时候,在进行生成图片的时候渐变的文本不能正常的显示渐变内容