aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/window/innerheight/index.html
blob: d177fd0cd7f6db3f982f64164b5411dde3bcb126 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---
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>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>1</td>
   <td>{{CompatGeckoDesktop(1.0)}}</td>
   <td>9</td>
   <td>9</td>
   <td>3</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>1</td>
   <td>{{CompatGeckoMobile(1.0)}}</td>
   <td>9</td>
   <td>9</td>
   <td>3</td>
  </tr>
 </tbody>
</table>
</div>

<h3 id="Gecko_note" name="Gecko_note">Gecko 备注</h3>

<p>从 Firefox 4 到 Firefox 24,该属性有 bug,而且某种情况下,会在页面加载前给出一个错误的值,查看 {{bug(641188)}}</p>

<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>