Javascript html2canvas选项类型:';视图';仍然渲染全身
我只想从库html2canvas.js中获取视口截图,将选项类型设置为“视图”应该可以做到这一点,但我仍然可以获得整个身体 我真的不明白为什么这不起作用 以下是我当前运行的代码:Javascript html2canvas选项类型:';视图';仍然渲染全身,javascript,html2canvas,Javascript,Html2canvas,我只想从库html2canvas.js中获取视口截图,将选项类型设置为“视图”应该可以做到这一点,但我仍然可以获得整个身体 我真的不明白为什么这不起作用 以下是我当前运行的代码: html2canvas(document.body, { type: 'view' }).then(function(canvas) { var img = canvas.toDataURL("image/png"); $('.ticket-img').attr('src', img); }); 没有
html2canvas(document.body, { type: 'view' }).then(function(canvas) {
var img = canvas.toDataURL("image/png");
$('.ticket-img').attr('src', img);
});
没有像
{type:'view'}
这样的选项。如果您正试图捕获用户可见的内容,则没有确切的设置
我可能会说你需要在截图之后处理输出。因此,拍摄屏幕截图,然后使用window scrollX/scrollY和window width/height裁剪生成的画布
差不多
function clip( srcCanvas, x, y, width, height ) {
var destCanvas = document.createElement("canvas");
var destCtx = destCanvas.getContext("2d");
destCanvas.width = width;
destCanvas.height = height;
destCtx.drawImage( srcCanvas.getImageData(x,y,width,height), 0, 0 );
return destCanvas;
}