html2canvas 介绍
html2canvas可以通过纯js对浏览器端经行截屏,但截图的精确度还有待提高,部分css不可识别,所以在canvas中不能完美呈现原画面样式 。
html2canvas兼容性:
Firefox 3.5+
Google Chrome
Opera 12+
IE9+
Safari 6+
html2canvas使用
1、安装npm install --save html2canvas//或者yarn add html2canvas2、使用html2canvas 的使用非常简单,简单到只需要传入一个 DOM 元素,然后通过回调拿到 canvas html:<div id="capture" padding: 10px; background: #f5da55"><h4 color: #000; ">Hello world!</h4></div>js:html2canvas(document.querySelector("#capture")).then(canvas => {document.body.appendChild(canvas)});html2canvas注意点
1.html2canvas 通过解析元素实际的样式来生成 canvas 图片内容,因此它对元素实际的布局和视觉显示有要求。如果要完整截图,最好将元素从文档流中独立出来(例如 position:absolute)
2.默认生成的 canvas 图片在 retina 设备上显示很模糊,处理成 2 倍图能解决这个问题
网站地址:https://html2canvas.hertzen.com/
GitHub:https://github.com/niklasvh/html2canvas
网站描述:一个js实现从浏览器网页截图的开源库
html2canvas
官方网站:https://html2canvas.hertzen.com/
小编说
以上是编程之家为你收集整理的html2canvas全部内容。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。