本篇文章给大家分享的是有关使用html2canvas怎么截图浏览器,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。作用html2canvas可以通过纯js对浏览器端经行截屏,但截
本篇文章给大家分享的是有关使用html2canvas怎么截图浏览器,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
作用
html2canvas可以通过纯js对浏览器端经行截屏,但截图的精确度还有待提高,部分CSS不可识别,所以在canvas中不能完美呈现原画面样式
.book_inf{ position: relative; overflow : hidden; text-overflow: ellipsis; display: -WEBkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
支持的浏览器
Firefox 3.5+
Google Chrome
Opera 12+
IE9+
Safari 6+
基本语法
function screenshotsImg(){ html2canvas(document.querySelector("#screenshots"),{ backgroundColor: 'transparent',// 设置背景透明 }).then(canvas => { canvasTurnImg(canvas) //保存的图片格式转换方法 }); }
可用配置项
参数名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
allowTaint | boolean | false | Whether to allow cross-origin images to taint the canvas---允许跨域 |
background | string | #fff | Canvas background color, if none is specified in DOM. Set undefined for transparent---canvas的背景颜色,如果没有设定默认白色此处被坑,我改为backgroundColor可用 |
height | number | null | Define the heigt of the canvas in pixels. If null, renders with full height of the window.---canvas高度设定 |
letterRendering | boolean | false | Whether to render each letter seperately. Necessary if letter-spacing is used.---在设置了字间距的时候有用 |
logging | boolean | false | Whether to log events in the console.---在console.log()中输出信息 |
proxy | string | undefined | Url to the proxy which is to be used for loading cross-origin images. If left empty, cross-origin images won't be loaded.---代理地址 |
taintTest | boolean | true | Whether to test each image if it taints the canvas before drawing them---是否在渲染前测试图片 |
timeout | number | 0 | Timeout for loading images, in milliseconds. Setting it to 0 will result in no timeout.---图片加载延迟,默认延迟为0,单位毫秒 |
width | number | null | Define the width of the canvas in pixels. If null, renders with full width of the window.---canvas宽度 |
useCORS | boolean | false | Whether to attempt to load cross-origin images as CORS served, before reverting back to proxy--跨域代理 |
设置图片格式
从canvas中直接提取图片元数据
// 图片导出为 png 格式 var type = 'png'; var imgData = canvas.toDataURL(type);
将mime-type改为image/octet-stream,强制让浏览器直接download
var _fixType = function(type) { type = type.toLowerCase().replace(/jpg/i, 'jpeg'); var r = type.match(/png|jpeg|bmp|gif/)[0]; return 'image/' + r;}; // 加工image data,替换mime typeimgData = imgData.replace(_fixType(type),'image/octet-stream');
图片download到本地
var saveFile = function(data, filename){ var save_link = document.createElementNS('Http://www.w3.org/1999/xhtml', 'a'); save_link.href = data; save_link.download = filename; var event = document.createEvent('MouseEvents'); event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); save_link.dispatchEvent(event);}; // 下载后的文件名var filename = 'baidufe_' + (new Date()).getTime() + '.' + type;// downloadsaveFile(imgData,filename);
以上就是使用html2canvas怎么截图浏览器,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注编程网精选频道。
--结束END--
本文标题: 使用html2canvas怎么截图浏览器
本文链接: https://www.lsjlt.com/news/257872.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
一口价域名售卖能注册吗?域名是网站的标识,简短且易于记忆,为在线用户提供了访问我们网站的简单路径。一口价是在域名交易中一种常见的模式,而这种通常是针对已经被注册的域名转售给其他人的一种方式。
一口价域名买卖的过程通常包括以下几个步骤:
1.寻找:买家需要在域名售卖平台上找到心仪的一口价域名。平台通常会为每个可售的域名提供详细的描述,包括价格、年龄、流
443px" 443px) https://www.west.cn/docs/wp-content/uploads/2024/04/SEO图片294.jpg https://www.west.cn/docs/wp-content/uploads/2024/04/SEO图片294-768x413.jpg 域名售卖 域名一口价售卖 游戏音频 赋值/切片 框架优势 评估指南 项目规模
0