html2canvas截图截不全是怎么回事?

比如说,我的内容区域为3000px的高度,但是html2canvas只能截取屏幕的可视区域。
哪个大佬知道怎么解决吗?

阅读 8.1k
2 个回答

修改源码:自定义宽高
var width = options.width != null ? options.width : node.ownerDocument.defaultView.innerWidth;

var height = options.height != null ? options.height : node.ownerDocument.defaultView.innerHeight;
return renderDocument(node.ownerDocument, options, width, height, index).then(function (canvas) {**

if (typeof(options.onrendered) === "function") {
    log("options.onrendered is deprecated, html2canvas returns a Promise containing the canvas");
    options.onrendered(canvas);
}
return canvas;

});

调用:
var height = $('#htmlcanvas').outerHeight(true);

     if(height <= 650 || height>=1024){height += 53;}//适配
     html2canvas($("#htmlcanvas"),{ 
         height:height,
        // window.devicePixelRatio是设备像素比

// dpi: 192,//放大像素(2倍),以免图片模糊

         dpi: window.devicePixelRatio,
     }).then(function(....)}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题