HTML2Canvas converting overflowed content to image

前端 未结 2 1342
甜味超标
甜味超标 2020-12-14 22:13

I have a div which is pretty overflowed. It basically includes a big organization chart. What I want to do is exporting whole content of div rather than visible part with ht

2条回答
  •  温柔的废话
    2020-12-14 23:07

    I don't know if there's a straightforward option in html2canvas to do this (i.e. an option to set all overflow to visible) but a roundabout way might be to set the parent of the diagram element's overflow property to visible when your export function is called, then set it back to hidden again on html2canvas' onrendered callback so that the user has minimal time to perceive it:

    function export(){ 
    document.getElementById('diagram').parentNode.style.overflow = 'visible'; //might need to do this to grandparent nodes as well, possibly.
        html2canvas( [ document.getElementById('diagram') ], {
            onrendered: function(canvas) {
                document.getElementById('diagram').parentNode.style.overflow = 'hidden';
                var dataUrl = canvas.toDataURL();
                window.open(dataUrl, "toDataURL() image", "width=800, height=800");
                //Canvas2Image.saveAsPNG(canvas);
            }
         });
    }
    

提交回复
热议问题