{"id":113,"date":"2025-11-23T10:09:16","date_gmt":"2025-11-23T02:09:16","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=113"},"modified":"2025-11-23T10:09:16","modified_gmt":"2025-11-23T02:09:16","slug":"%e5%85%b3%e4%ba%8edocument-body-clientheight%e8%bf%94%e5%9b%9e%e5%80%bc%e4%b8%ba0%e7%9a%84%e5%ae%8c%e7%be%8e%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/11\/23\/%e5%85%b3%e4%ba%8edocument-body-clientheight%e8%bf%94%e5%9b%9e%e5%80%bc%e4%b8%ba0%e7%9a%84%e5%ae%8c%e7%be%8e%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88\/","title":{"rendered":"\u5173\u4e8edocument.body.clientHeight\u8fd4\u56de\u503c\u4e3a0\u7684\u5b8c\u7f8e\u89e3\u51b3\u65b9\u6848"},"content":{"rendered":"\n<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u4efd <strong>\u5168\u9762\u3001\u7a33\u5b9a\u3001\u53ef\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u4f7f\u7528<\/strong> \u7684<br><code>document.body.clientHeight \u8fd4\u56de 0<\/code> \u7684 <strong>\u5b8c\u7f8e\u89e3\u51b3\u65b9\u6848\u5408\u96c6\uff08\u542b\u539f\u56e0 + \u4fee\u590d\u65b9\u5f0f + \u63a8\u8350\u5199\u6cd5\uff09<\/strong>\u3002<\/p>\n\n\n\n<p>\u9002\u7528\u4e8e\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>H5 \u7f51\u9875<\/li>\n\n\n\n<li>uni-app H5 \u7aef<\/li>\n\n\n\n<li>Vue\/React\/\u539f\u751f JS<br>\u5c24\u5176\u662f\u5728 <strong>\u9875\u9762\u521d\u59cb\u5316\u65f6\u8bfb\u53d6\u9ad8\u5ea6\u4e3a 0<\/strong> \u7684\u60c5\u51b5\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udd25 \u4e00\u3001\u4e3a\u4ec0\u4e48 document.body.clientHeight \u4f1a\u8fd4\u56de 0\uff1f<\/h1>\n\n\n\n<p>\u6700\u5e38\u89c1\u539f\u56e0\u53ea\u6709\u4e09\u4e2a\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u2460 CSS \u4f7f\u7528\u4e86 <code>html, body { height: 100%; }<\/code><\/strong><\/h3>\n\n\n\n<p>\u5982\u679c <code>html<\/code> \u9ad8\u5ea6\u6ca1\u6709\u5185\u5bb9\u652f\u6491\uff0cbody \u5c31\u4f1a\u88ab\u6491\u5230 0 \u2192 clientHeight = 0\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u2461 DOM \u672a\u5b8c\u6210\u5e03\u5c40\uff08\u672a\u6e32\u67d3\uff09<\/strong><\/h3>\n\n\n\n<p>\u5728\u9875\u9762\u521d\u59cb\u5316\uff08\u5982 mounted \/ onLoad\uff09\u8fc7\u65e9\u8bfb\u53d6\u9ad8\u5ea6\uff0c\u4f1a\u5f97\u5230 0\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u2462 \u5728 iframe \/ \u67d0\u4e9b WebView\uff08\u7279\u522b\u662f uni-app H5\uff09\u4e2d<\/strong><\/h3>\n\n\n\n<p>body \u9ad8\u5ea6\u88ab\u6846\u67b6\u63a5\u7ba1\uff0c\u771f\u5b9e\u9ad8\u5ea6\u7531\u5916\u5c42\u63a7\u5236\uff0c\u56e0\u6b64\u8fd4\u56de 0\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2b50 \u4e8c\u3001\u6700\u5b8c\u7f8e\u3001\u901a\u7528\u7684\u89e3\u51b3\u65b9\u6848\uff08\u63a8\u8350\u4f18\u5148\u7ea7\u6700\u9ad8\uff09<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u2714 <strong>\u65b9\u6848 1\uff1a\u6539\u7528 <code>document.documentElement.clientHeight<\/code><\/strong><\/h2>\n\n\n\n<p>\u8fd9\u662f\u517c\u5bb9\u6027\u6700\u5f3a\u3001\u6700\u7a33\u5b9a\u7684\u65b9\u6848\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet h = document.documentElement.clientHeight;\n\n<\/pre><\/div>\n\n\n<p><code>documentElement<\/code>\uff08html\uff09\u80fd\u4fdd\u8bc1\u6c38\u8fdc\u5b58\u5728\u9ad8\u5ea6\uff0c\u4e0d\u53d7 body \u7684 height:100% \u5f71\u54cd\u3002<br><strong>99% \u7684\u9879\u76ee\u90fd\u5e94\u8be5\u6539\u7528\u8fd9\u4e2a\u3002<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2b50 \u4e09\u3001\u901a\u7528\u7684\u8865\u6551\u65b9\u6848\uff08\u9002\u5408\u5df2\u7ecf\u5199\u6b7b body \u9ad8\u5ea6\u7684\u9879\u76ee\uff09<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u2714 <strong>\u65b9\u6848 2\uff1a\u786e\u4fdd body \u80fd\u6491\u5f00\u9ad8\u5ea6<\/strong><\/h2>\n\n\n\n<p>\u901a\u5e38\u662f\u56e0\u4e3a\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nhtml, body {\n  height: 100%;\n  padding: 0;\n  margin: 0;\n}\n\n<\/pre><\/div>\n\n\n<p>\u4f46 body \u91cc\u9762\u6ca1\u5185\u5bb9\uff0c\u6240\u4ee5\u9ad8\u5ea6\u4e3a 0\u3002<br><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a\u4e3a body \u52a0\u6700\u5c0f\u9ad8\u5ea6\uff1a<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nbody {\n  min-height: 100vh;\n}\n\n<\/pre><\/div>\n\n\n<p>\u6216\u8005\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nhtml, body {\n  height: auto !important;\n}\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2b50 \u56db\u3001\u9002\u7528\u4e8e Vue \/ uni-app \u7684\u6700\u4f73\u65f6\u673a\u65b9\u6848<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u2714 <strong>\u65b9\u6848 3\uff1a\u7b49 DOM \u6e32\u67d3\u540e\u518d\u83b7\u53d6\u9ad8\u5ea6<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Vue\/uni-app \u4e2d\uff1a<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nthis.$nextTick(() =&gt; {\n  console.log(document.body.clientHeight);\n});\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u539f\u751f JS\uff1a<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nwindow.onload = () =&gt; {\n  console.log(document.body.clientHeight);\n};\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u6216\u4e8b\u4ef6\u76d1\u542c\uff1a<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ndocument.addEventListener(&#039;DOMContentLoaded&#039;, () =&gt; {\n  console.log(document.body.clientHeight);\n});\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2b50 \u4e94\u3001\u5728 uni-app H5 \u4e2d\u7684\u7279\u522b\u6ce8\u610f\u4e8b\u9879\uff08\u5173\u952e\uff09<\/h1>\n\n\n\n<p>uni-app \u8fd0\u884c\u5728 WebView \u4e0b\uff0cbody \u9ed8\u8ba4\u51e0\u4e4e\u662f <strong>0 \u9ad8\u5ea6<\/strong>\uff08HBuilderX \u4f1a\u91cd\u5199\u6837\u5f0f\uff09\u3002<\/p>\n\n\n\n<p>\ud83d\udc49 \u5fc5\u987b\u6539\u7528\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ndocument.documentElement.clientHeight\n\n<\/pre><\/div>\n\n\n<p>\u800c\u4e0d\u8981\u7528\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ndocument.body.clientHeight  \/\/ \u7ecf\u5e38\u8fd4\u56de 0\n\n<\/pre><\/div>\n\n\n<p>\u6216\u8005\u83b7\u53d6\u7a97\u4f53\u53ef\u89c6\u9ad8\u5ea6\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nuni.getSystemInfo({\n  success: res =&gt; {\n    console.log(&#039;windowHeight:&#039;, res.windowHeight);\n  }\n});\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\u2b50 \u516d\u3001\u7ec8\u6781\u515c\u5e95\u65b9\u6848\uff08\u4fdd\u5e95\u4e0d\u4f1a\u5931\u8d25\uff09<\/h1>\n\n\n\n<p>\u5982\u679c\u4f60\u5fc5\u987b\u83b7\u53d6\u771f\u5b9e\u9875\u9762\u9ad8\u5ea6\uff08\u6574\u4e2a\u5185\u5bb9\u9ad8\u5ea6\uff09\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlet height = Math.max(\n  document.body.scrollHeight,\n  document.documentElement.scrollHeight,\n  document.body.offsetHeight,\n  document.documentElement.offsetHeight,\n  document.body.clientHeight,\n  document.documentElement.clientHeight\n);\n\n<\/pre><\/div>\n\n\n<p>\u8fd9\u4e2a\u662f\u4e1a\u5185\u901a\u7528\u7684\u201c\u5168\u517c\u5bb9\u65b9\u6848\u201d\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83c\udfaf \u4e03\u3001\u6700\u4f73\u5b9e\u8df5\u603b\u7ed3\uff08\u5fc5\u770b\uff09<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">\u2714 \u6700\u63a8\u8350\u7528\uff1a<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ndocument.documentElement.clientHeight\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u2714 uni-app H5 \u5f3a\u70c8\u63a8\u8350\uff1a<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nuni.getSystemInfo()\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u2714 \u9875\u9762\u521d\u59cb\u5316\u83b7\u53d6\u9ad8\u5ea6\uff1a<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nthis.$nextTick(() =&gt; {...})\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u2714 \u5982\u5fc5\u987b\u83b7\u53d6\u5185\u5bb9\u603b\u9ad8\u5ea6\uff1a<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nMath.max(...\u516d\u9879)\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u4efd \u5168\u9762\u3001\u7a33\u5b9a\u3001\u53ef\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u4f7f\u7528 \u7684document.body.cl&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/11\/23\/%e5%85%b3%e4%ba%8edocument-body-clientheight%e8%bf%94%e5%9b%9e%e5%80%bc%e4%b8%ba0%e7%9a%84%e5%ae%8c%e7%be%8e%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-113","post","type-post","status-publish","format-standard","hentry","category-html5"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=113"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/113\/revisions"}],"predecessor-version":[{"id":114,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/113\/revisions\/114"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}