Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[js] 第116天 如何使用js来截图?怎样截可见区域和整个页面? #1047

Open
haizhilin2013 opened this issue Aug 9, 2019 · 5 comments
Labels
js JavaScript

Comments

@haizhilin2013
Copy link
Collaborator

第116天 如何使用js来截图?怎样截可见区域和整个页面?

@haizhilin2013 haizhilin2013 added the js JavaScript label Aug 9, 2019
@LinStan
Copy link

LinStan commented Aug 10, 2019

可以基于html2canvas 和 canvas2image 两个第三方类实现截图。

如果打算截取整个页面 可以直接设定

html2canvas(document.body).then(function (canvas) {
        document.body.appendChild(canvas);
      });

如果打算截取可见区域 额外设置一下宽高即可

width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight,
y: document.documentElement.scrollTop

@ghost
Copy link

ghost commented Aug 10, 2019

这种东西太hack了...browser 上搞纯属自虐

nodejs 可以考虑一系列 headless 库,例如 puppeteer 和 phantomjs

@zhuyuedlut
Copy link

@t532 楼上说的对,但是更推荐用puppeteer,phantomjs已经停止维护了,在一些比较新的ES的语法上会出现一些问题

@CaptainJon
Copy link

不知道,目前市面上的库html2canvas 和 canvas2image 都不能处理渐变色文字,不能算完美的库

@xiaoqiangz
Copy link

市面上html2canvas库用来截图比较多,截整个页面可传入body 如 :
html2canvas(document.body).then(function (canvas) {
document.body.appendChild(canvas);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js JavaScript
Projects
None yet
Development

No branches or pull requests

5 participants