blob: 0a06678a037724f9e263ff86e8835c522085f93e (
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
|
---
title: Screen.orientation
slug: Web/API/Screen/orientation
tags:
- API
- Experimental
- Screen Orientation
- screen
translation_of: Web/API/Screen/orientation
---
<p>{{APIRef("Screen Orientation API")}}{{SeeCompatTable}}</p>
<p><strong><code>orientation</code></strong> 是 {{DOMxRef("Screen")}} 接口的一个只读属性,返回屏幕当前的方向。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox">var <var>orientation</var> = window.screen.orientation;</pre>
<h3 id="返回值">返回值</h3>
<p>一个 {{DOMxRef("ScreenOrientation")}} 的实例,表示屏幕的方向。</p>
<p>注意在更早的、有前缀的版本中会返回一个 {{DOMxRef("DOMString")}} 值,相当于 {{DOMxRef("ScreenOrientation.type")}} 的值。</p>
<h2 id="示例">示例</h2>
<pre class="brush: js;">var orientation = (screen.orientation || {}).type || screen.mozOrientation || screen.msOrientation;
if (orientation === "landscape-primary") {
console.log("That looks good.");
} else if (orientation === "landscape-secondary") {
console.log("Mmmh... the screen is upside down!");
} else if (orientation === "portrait-secondary" || orientation === "portrait-primary") {
console.log("Mmmh... you should rotate your device to landscape");
} else if (orientation === undefined) {
console.log("The orientation API isn't supported in this browser :(");
}
</pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
<th scope="col">备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('Screen Orientation', '#dom-screen-orientation', 'orientation')}}</td>
<td>{{Spec2('Screen Orientation')}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("api.Screen.orientation")}}</p>
<h2 id="参见">参见</h2>
<ul>
<li>{{DOMxRef("ScreenOrientation")}}</li>
<li>{{DOMxRef("Screen.onorientationchange")}}</li>
<li><a href="/en-US/docs/Managing_screen_orientation">Managing screen orientation</a></li>
</ul>
|