aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/window/innerheight/index.html
blob: 19531d83d5100211a83c76bb4ad00f760899a25e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
title: Window.innerHeight
slug: Web/API/Window/innerHeight
translation_of: Web/API/Window/innerHeight
---
<div>{{APIRef}}</div>

<h2 id="Summary" name="Summary">概述</h2>

<p>浏览器窗口的视口(viewport)高度(以像素为单位);如果有水平滚动条,也包括滚动条高度。</p>

<div class="note"><strong>Note:</strong> If you use {{ifmethod("nsIDOMWindowUtils", "setCSSViewport")}} to set the virtual window size for page layout purposes, the value returned by this property corresponds to the viewport height set using that method.</div>

<h2 id="Syntax" name="Syntax">语法</h2>

<pre class="syntaxbox">var <var>intViewportHeight</var> = window.innerHeight;</pre>

<h3 id="Value" name="Value"></h3>

<p><code>intViewportHeight</code> 为浏览器窗口的视口的高度。</p>

<p><code>window.innerHeight</code> 属性为只读,且没有默认值。</p>

<h2 id="Notes" name="Notes">备注</h2>

<p>任何窗口对象,如<font face="Courier New, Andale Mono, monospace"> </font>{{domxref("window")}}、frame、frameset 或 secondary window 都支持 <code>innerHeight</code> 属性。</p>

<p>有一个<a class="link-https" href="https://bugzilla.mozilla.org/show_bug.cgi?id=189112#c7" title="https://bugzilla.mozilla.org/show_bug.cgi?id=189112#c7">算法</a>用来获取不包括水平滚动条的视口高度。</p>

<h2 id="Example" name="Example">例子</h2>

<h3 id="假设有一个_frameset">假设有一个 frameset</h3>

<pre class="brush:js">var intFrameHeight = window.innerHeight; // or

var intFrameHeight = self.innerHeight;
// 返回frameset里面的frame视口的高度

var intFramesetHeight = parent.innerHeight;
// 返回上一级frameset的视口的高度

var intOuterFramesetHeight = top.innerHeight;
// 返回最外部frameset的视口的高度
</pre>

<p>{{todo("link to an interactive demo here")}}</p>

<p>改变一个窗口的大小,可以查看 {{domxref("window.resizeBy()")}}{{domxref("window.resizeTo()")}}</p>

<p>想获取窗口的外层高度(outer height),即整个浏览器窗口的高度,请查看 {{domxref("window.outerHeight")}}</p>

<h3 id="Graphical_example" name="Graphical_example">图像示例</h3>

<p>下面的示意图展示了 <code>outerHeight</code> 和 <code>innerHeight</code> 两者的区别。</p>

<p><img alt="innerHeight vs outerHeight illustration" src="/@api/deki/files/213/=FirefoxInnerVsOuterHeight2.png"></p>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

{{Compat("api.Window.innerHeight")}}

<h2 id="Standards_information" name="Standards_information">标准相关信息</h2>

<p>DOM Level 0。不属于任何 W3C 技术规范或推荐。</p>

<h2 id="See_also" name="See_also">相关链接</h2>

<ul>
 <li>{{domxref("window.innerWidth")}}</li>
 <li>{{domxref("window.outerHeight")}}</li>
 <li>{{domxref("window.outerWidth")}}</li>
</ul>