-
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
How to render full of hidden part in 'overflow:auto' div #60
Comments
There currently isn't an option to render the page with specific options, so you'll need to modify the page to look the way you want it to render. In other words, if you remove the height/width limit, run html2canvas, and then set the height/width back to the value it was, you should achieve what you are looking for. |
Thank you very much.... I shall try what you said... |
I tried for a long time... But it makes a lot of problem... I could not achieve what you said. I found out that it works well when it is 'body' even if there is scrolling... I want to achieve the same for a div which has elements with scrolling... If you could help me out with this issue it would be of great help for me... I am looking forward to your comments... |
@niklasvh, I am having the same issue, and the only workarounds I've are to either shrink the width of the target element before the call to http://jsfiddle.net/fMeRC/1/ (this particular example works just for Chrome; you have to fiddle with the width to see the issue in other browsers) This basically only happens when the element is wider than the window or |
Tried childElement or set "overflow=visible" and after set "overflow=auto|hidden|inherit" ? childElement without style, only to receive the contents of the div with overflow: <div id="main"><!--// main div -->
<div class="mainContent"><!--// div without style (height: auto, width: auto, margin: 0, padding: 0) -->
...content... html2canvas([$("#main div.mainContent").get(0)],...) |
Thanks for the suggestions, @brcontainer. I had tried the html2canvas( targetElement, {
onpreloaded: function(){ /* set parent overflow to visible */},
onparsed: function(){ /* reset parent overflow */ },
// ... onrendered, etc.
}); This sets the overflow to 'visible' only for (what I think is) the shortest amount of time necessary for h2c to properly parse the target, thus eliminating the flash almost entirely, at least in my case. That is, we no longer have to wait for the canvas rendering step to finish before resetting/re-hiding the overflow. I have no idea if this modified approach will work for everyone, but I do think it's a nicer workaround than calling In any case, this is still a real bug that I'd like to see properly fixed. (Especially since neither workaround seems to work correctly for me in IE9&10, at least--haven't tried in IE11.) Note: The aforementioned workaround would not work with the newest version that is currently in master. I haven't tested, but it looks like you would need to make use of the |
I do not understand why use this way you did, it would be better like this: function SnapShotDOM(target,call){
var data = {};
//use jquery or getComputedStyle|style.overflow
data.overflow = /*get overflow property*/;
data.width = /*get width property*/;
data.height = /*get height property*/;
data.maxWidth = /*get maxWidth property*/;
data.maxHeight = /*get maxHeight property*/;
target.style.overflow="visible !important";
target.style.height="auto !important";
target.style.maxHeight="auto !important";
html2canvas(target, {
"onrendered": function(canvas) {
target.style.overflow = data.overflow;
target.style.width = data.width;
target.style.height = data.height;
target.style.maxWidth = data.maxWidth;
target.style.maxHeight = data.maxHeight;
call(canvas);
}
});
}
SnapShotDOM(document.body,function(canvas){
console.log(canvas);
}); or use class: <style>
*.html2canvasreset{
overflow: visible !important;
width: auto !important;
height: auto !important;
max-height: auto !important;
}
</style>
<script>
function SnapShotDOM(target,call){
var data = target.className;
target.className += " html2canvasreset";//set className - Jquery: $(target).addClass("html2canvasreset");
html2canvas(target, {
"onrendered": function(canvas) {
target.className = data;//old className - Jquery: $(target).removeClass("html2canvasreset");
call(canvas);
}
});
}
SnapShotDOM(document.body,function(canvas){
console.log(canvas);
});
</script> |
The reason I don't put anything related to overflow in |
I was referring to "onpreloaded". try this: function SnapShotDOM(target,call){
var data = target.className;
target.className += " html2canvasreset";//set className - Jquery: $(target).addClass("html2canvasreset");
html2canvas(target, {
"onparsed": function() {
target.className = data;//old className - Jquery: $(target).removeClass("html2canvasreset");
},
"onrendered": function(canvas) {
call(canvas);
}
});
}
SnapShotDOM(document.body,function(canvas){
console.log(canvas);
}); |
My use of |
@niklasvh, is this issue at all related to the TODO found here ( |
what version did you guys used?.. i can find onparsed and onpreloaded method in my version.. |
it's not working. |
@uriklar It's working for horizontal scroll not for vertical. Checkout my div. There are three different elements there. |
@uriklar the solution you suggest is also not working when i scroll down the div and click on totally visible. |
What about setting the height of #text div to auto before render and resetting it after? That will work. |
I was still having issues with overflow in the most recent release (0.5.0-beta4). I took @usmonster's workaround and adapted it to the recent changes to h2c and Promises (as described in @usmonster's note):
So without altering the actual DOM of your webpage, you can alter the cloned document used for rendering by h2c utilizing the
|
The only thing that worked for me was putting the canvas in an iframe, calling html2canvas inside that, calling toDataURL() on the canvas, and then passing that image back to the top window using a callback. I suppose you could also pass back a canvas object. |
This can solute the question about overflow of screen(both width and height) |
xzw123 has a bad solution: setting |
Jordan, how did you end up using canvas in an iframe? I'm attempting it now. I think this should be the final solution in html2canvas... the iframe communication should be made invisible external to the API. |
Ah yes, doing it in an iframe with |
+1 |
This comment has been minimized.
This comment has been minimized.
i still not get it, but for my issue is the image get cut off. when using chrome Version 54.0.2840.99 m
but when using Mozilla 50.0.2, its working fine without zoom out. (100% image), i dont know why.
|
Finally i solve this issue by adding
so
hope it solve your own issue. |
onclone maybe be the correct method. You can change css to get what you want.... |
Hi All, I have div which is scrollable. When i send the div input as canvas parameter, it just rendering what is avialable in viewport. I gone through all solutions. I didnt understand. Can anyone tell how to take entire content in div as screenshot. |
@ruthraprakash, I had a similar issue. This works for my simple purposes on the latest version: function fullhtml2canvas(el) {
return new Promise(resolve => {
html2canvas(el, {
width: el.scrollWidth,
height: el.scrollHeight,
}).then(canvas => {
resolve(canvas);
});
});
} |
I have an issue with taking a screenshot of the timeline chart. I am not geeting the x axis value. it is just creating the image of the timline chart.
`
|
Please can you show me how you got body to work |
|
-> Add CSS overflow-y: scroll; to HTML element pdfHTML
|
|
This is a current answer! “ windowWidth: window.innerWidth ” This configuration can address the display problem associated with overflow: auto"👍 |
I have a div which contains all the elements that have to be converted into an image. And that div is set to 'overflow:auto'. I want to know how I can export all the elements(even hidden in the scrolling) to an image. I appreciate and welcome all your comments and answers...... Thanks in advance...
The text was updated successfully, but these errors were encountered: