niklasvh / html2canvas

Screenshots with JavaScript
https://html2canvas.hertzen.com/
MIT License
30.69k stars 4.82k forks source link

White space to left of captured image #2510

Open jimiswells opened 3 years ago

jimiswells commented 3 years ago

On some occasions I'm getting a thick white line to the left of the image displaying in my div which is captured from another div offscreen.. capture code below -

Screen Shot 2021-04-17 at 13 26 40

 html2canvas(document.querySelector("#capture"), {
      scrollX: -window.scrollX,
      scrollY: -window.scrollY,
      windowWidth: document.documentElement.offsetWidth,
      windowHeight: document.documentElement.offsetHeight,
    }).then((canvas) => {
      window.scrollTo(0, 0);
      var data = canvas.toDataURL("image/png");
      var img = $(`<img src="${data}" id="dynamic">`);

      $("#displayCanvas").addClass("imgRendered");
      $("#displayCanvas").addClass("bg-grey");
      $("#displayCanvas").append(img);
    });
pagarevijayy commented 3 years ago

same but on the bottom.

553082694 commented 3 years ago

window.scrollTo(0, 0);

before html2canvas()

valtism commented 3 years ago

Yep, seems to be because of the scroll. This is annoying because when I have a mouse plugged in (macOS) the presence of the fixed scrollbar on the right means that all of the images come out with a bar on their left.

I was able to get around this by setting document.documentElement.style.overflow = "hidden" before the call, and document.documentElement.style.overflow = "" after.