繁体   English   中英

如何在不使用Canvas的情况下将HTML页面中的div转换为Image?

[英]How to convert a div in a HTML page into Image without using Canvas?

如何不使用画布将div元素转换为图像?

组织当前使用的浏览器是IE8,并且canvas与之不兼容。

我正在寻找仅使用JavaScript / jQuery的解决方案。

是的,我们可以使用dom-to-image将div元素转换为图像

dom-to-image是一个库,可以将任意DOM节点转换为用JavaScript编写的矢量(SVG)或光栅(PNG或JPEG)图像。

var node = document.getElementById('my-node'); //assign our dom id to a variable
domtoimage.toPng(node)
.then(function (dataUrl) {
    var img = new Image();
    img.src = dataUrl;
    document.body.appendChild(img); //append the converted image to html body
})
.catch(function (error) {
    console.error('oops, something went wrong!', error);
});

这是将html dom转换为图像的简单示例

暂无
暂无

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

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