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 元素,然后通过回调拿到 canvashtml:<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/
如果觉得 网站内容还不错,欢迎将 网站 推荐给程序员好友。
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did175599