admin管理员组文章数量:1279207
Is there any way of getting the full page height including scrollable content?
For example, in the page below I have a height of 613px, but with a lot more content that was scrolled out. If a get the value of document.documentElement.scrollHeight
it gives me the same 613px. Is there any way I can actually get the full page height?
EDIT:
I've tried some of the answers, but somehow, for this page I always get the same height (/). Does someone know why?
Is there any way of getting the full page height including scrollable content?
For example, in the page below I have a height of 613px, but with a lot more content that was scrolled out. If a get the value of document.documentElement.scrollHeight
it gives me the same 613px. Is there any way I can actually get the full page height?
EDIT:
I've tried some of the answers, but somehow, for this page I always get the same height (https://material.angular.io/). Does someone know why?
Share Improve this question edited Sep 25, 2019 at 13:57 mordecai asked Sep 25, 2019 at 13:34 mordecaimordecai 5697 silver badges26 bronze badges 4- 3 stackoverflow./a/3044355/3953479, it should help – Rajeev Ranjan Commented Sep 25, 2019 at 13:36
- "The Element.scrollHeight read-only property is a measurement of the height of an element's content, including content not visible on the screen due to overflow." this should include your off screen content as well. – rlemon Commented Sep 25, 2019 at 13:37
-
1
I think its
document.body.clientHeight
– Dumisani Commented Sep 25, 2019 at 13:40 - 1 Possible duplicate of How to get document height and width without using jquery – nircraft Commented Sep 25, 2019 at 13:45
4 Answers
Reset to default 5This will give you a height of scrollable area too
(function() {
let pageHeight = 0;
function findHighestNode(nodesList) {
for (let i = nodesList.length - 1; i >= 0; i--) {
if (nodesList[i].scrollHeight && nodesList[i].clientHeight) {
var elHeight = Math.max(nodesList[i].scrollHeight, nodesList[i].clientHeight);
pageHeight = Math.max(elHeight, pageHeight);
}
if (nodesList[i].childNodes.length) findHighestNode(nodesList[i].childNodes);
}
}
findHighestNode(document.documentElement.childNodes);
console.log('You page hight it', pageHeight);
})();
try
window.outerHeight
I think this will help you to get window height with scrollable area.
Similar to @reachtokish, document.querySelector('body').scrollHeight
will give you the whole height of the scrollable page
With the developer tools console you can try it for this page
var pageHeight = document.documentElement.scrollHeight;
This looks like this
本文标签: htmlHow to get full page height with JavascriptStack Overflow
版权声明:本文标题:html - How to get full page height with Javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741264664a2368232.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论