When taking a screenshot of html2canvas, the dom element is set to the image captured after position absolute, and the content of this dom element cannot be captured.

problem description

When taking a screenshot of

html2canvas, the dom element is set to position absolute, and the content of this dom element cannot be captured

.

the environmental background of the problems and what methods you have tried

google did not find the answer, but you can intercept the dom content by removing the position:absolute of dom.

related codes

/ / Please paste the code text below (do not replace the code with pictures)

   var copyDom = targetDom;
    copyDom.css(
        {
            "background-image":"url("./bg03.jpg")"
        }
    );
   /* $("body").append(copyDom);//copybody*/
    var width = copyDom.offsetWidth;//dom
    var height = copyDom.offsetHeight;//dom
    var scale = 2;//
    var canvas = document.createElement("canvas");
    canvas.width = width*scale;//canvas
    canvas.height = height*scale;//canvas
    var content = canvas.getContext("2d");
    content.scale(scale,scale);
    var rect = copyDom.get(0).getBoundingClientRect();//
    content.translate(-rect.left,-rect.top);//context
    html2canvas(copyDom[0], {
       /* allowTaint:true,
        useCORS:true,
        tainTest:true,*/
        scale:scale,
        canvas:canvas,
        width:width,
        heigth:height,
        }).then(function (canvas) {
    downloadImage(canvas.toDataURL(),"xxx.png")
});

Apr.01,2021
This problem does occur in

html2canvas. This problem has been encountered in previous projects. The requirement is to click to generate a user-specific image (multiple pictures, user names, evaluation results, etc.), and the final solution is to write your own canvas solution (the canvas size is preferably 2 times the required size, and then reduced, otherwise the display will be blurred on high-resolution mobile phones), for reference only

.
Menu