-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Canvas rendered with a big blank offset if I scroll to the bottom of the captured element #1878
Comments
Me too |
me too |
1 similar comment
me too |
I also, when I scroll the page, the canvas will be blank, but when I not scroll, the canvas is ok, really want to know why? |
As long as the page scrolls, a blank space appears above the screenshot and the longer the scroll, the more blank |
Hey people ! I had the same problem, but I managed to fix it using explicit Cheers ! 🍻 |
Thanks! |
I was facing the same problem, but setting
As this is quite a hack it would be really great having this issue fixed! Cheers 🍻 |
me too. i have dialog, dialog position is fixed; body too height. use 1.0.0-rc.1, in Chrome it's good. in ios.use UIWebView it's bad. generator dialog img is transparent |
Hello, I'm facing the same problem. I have tried to set scrollY to 0, to (-window.scrollY), to a fixed value. But none of these solutions fixed my problem. I use HTML2Canvas with Angular, I don't face the problem in dev mode but only in prod mode. |
Maybe, like some of the others here you tried installing it using the caret ("^") version prefix? RC1 doesn't have the issue mentioned in this bug report. |
Thank you, that was my problem |
Cheers ! 🍻 |
If you want to support IE11 just use |
Hey guys, I'm having the same problem in |
This solution solved my problem |
None of these work for me, are there any other possible solutions? |
Only thing that worked for me was downgrading to 1.0.0-alpha.12. |
I was experiencing a few issues and downgrading to 1.0.0-alpha.12 did the trick for me too, thanks! |
Two ways worked for me:
|
It would be nice to have some e2e testing to avoid this issue to reappear... |
1.0.0-alpha.12 is ok in this issue, but I found it not ok in some other aspects such as font size... |
I just downgraded on 14/04/2020 to 1.0.0-alpha.12 and it is handling my screenshots of divs much better than the current version. I spent the last day tweaking the scroll and window and x and could never get it to work right on all divs. The downgrade works properly with simply height and width set. |
window.scrollTo(0, 0) before you do html2canvas. causes a "WTF" moment as the page (from the users perspective) jumps up and down, but this hack works! |
Doing this helped me:
|
for me none of the above works on iOS except for
|
Same here, was not able to get a proper render with any other settings changes, this was the solution!! Thank You!! |
Any latest solution for Safari? Need help |
|
Thanks but it did not fix the issue with iOS unfortunately, still you have to scroll to the top of the page, capture the screen and then scroll back! |
In my case, it happens in a pop-up modal on the Safari browser. The full div can be rendered (in the modal) on Chrome and Firefox. On Safari, when u scroll down of the modal, the bottom part of the captured element will be cut off. |
#render-me is the html fragment to be rendered. |
function setTimer(callback) {
setTimeout(function () {
window.scrollTo(0, 0); // this is working!
console.log("first");
callback();
}, 500);
}
setTimer(function () {
html2canvas(document.getElementById("some_id")).then((canvas) => {
saveAs(canvas.toDataURL("image/png", 1), "image_name.png");
console.log("second");
});
});
function saveAs(uri, filename) {
let link = document.createElement("a");
if (typeof link.download === "string") {
link.href = uri;
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} else {
window.open(uri);
}
} In my case, I tried everything above, but it didn't work well on mobile and iOS. So instead of adding scroll options, I chose the way to force the screen up using scrollTo. The setTimer function and callback function allow screen to be raised first and captured later synchronously. You can easily check the order of code execution through console.log. With this method, I checked that image capture works well as desired in mobile and iOS environments. |
Any updates on this? The closest I have got to a fix is the window.scrollTo(0, 0) which works nearly everywhere except for mobile when the address bar is expanded. For example, if you scroll down the address bar collapses and calling window.scrollTo(0, 0) sets to the top as I'd hope and no clipping. When the page first loads and the address bar is open I get a white gap along the bottom of the render however. |
I've found this solution to work well:
|
I found that scrollX/Y was unresponsive unless the element was position fixed as mentioned in the references. I found a solution but I am not happy with how round about it is
|
Wow! Thank you very much, you saved my life <3 |
tks this solution has resolved my problem |
This worked perfectly! |
My solution: const { width, height } = $dom.getBoundingClientRect();
const { x, y } = getPosition($dom);
const defaultOptions: Partial<html2canvasOptions> = {
useCORS: true,
backgroundColor: null,
width,
height,
x,
y,
}
const oCanvas = await html2canvas($dom, defaultOptions); getPosition: get the element postion relative to root export const getPosition = element => {
const currentTop = window.pageXOffset;
const currentLeft = window.pageYOffset;
if (element) {
if (element.getBoundingClientRect) {
const { top, left } = element.getBoundingClientRect();
return { x: left + currentLeft, y: top + currentTop };
} else {
// polyfill
let xPosition = 0;
let yPosition = 0;
while (element) {
xPosition += element.offsetLeft - element.scrollLeft + element.clientLeft;
yPosition += element.offsetTop - element.scrollTop + element.clientTop;
element = element.offsetParent;
}
return { x: xPosition, y: yPosition };
}
}
return {
x: 0,
y: 0,
};
}; This worked perfectly in my project! |
@if anyone can't predict whether target captured element will be inside of fixed or non-fixed and affected by window scroll I recommend a solution which we used for Painterro js paint plugin: devforth/painterro@bfee94d#diff-9745fe0b9d3e6feae056f29a5730e6fe548b33695e8968628fcd717c1e9ad03aR203 Thing is that I've fixed it by setting |
version: 1.0.0-rc.7
it works! |
wait a little works for me! version: 1.0.0-rc.7
|
CSS:
JS Function:
...of course, overflow-x: hidden may cause other undesirable outcomes.
CSS:
JS Function:
|
this solution works |
Você pode adicionar os seguintes estilos à caixa: |
window.scrollTo(0, 0); |
Bug reports:
In 1.0.0-rc.3
If I scroll to the top of the page (where the element starts), it works perfectly.
Wrong: https://ibb.co/8Y9SnTV (scrolling to the bottom of the element)
Good: https://ibb.co/7z1903r (scrolling to the top of the element)
In 1.0.0-rc.1
Works perfectly, there is no need to scroll.
Specifications:
The text was updated successfully, but these errors were encountered: