aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/api/screen/orientation/index.html
blob: eafa89a7037a6b21904411bf780f900b025acf6d (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
---
title: Screen.orientation
slug: Web/API/Screen/orientation
translation_of: Web/API/Screen/orientation
---
<div>{{APIRef("CSSOM View")}}{{SeeCompatTable}}</div>

<p><code>Screen.orientation</code> 屬性可以取得螢幕目前的方向。</p>

<h2 id="語法">語法</h2>

<pre class="syntaxbox">var orientation = window.screen.orientation.type;
</pre>

<h2 id="回傳值">回傳值</h2>

<p>回傳值為一個代表螢幕方向的字串,可能是 <code>portrait-primary</code><code>portrait-secondary</code><code>landscape-primary</code><code>landscape-secondary</code>(請參考 {{domxref("window.screen.lockOrientation","lockOrientation")}} 以瞭解更多資訊)。</p>

<h2 id="範例">範例</h2>

<pre class="brush: js">var orientation = screen.orientation || screen.mozOrientation || screen.msOrientation;

if (orientation.type === "landscape-primary") {
  console.log("That looks good.");
} else if (orientation.type === "landscape-secondary") {
  console.log("Mmmh... the screen is upside down!");
} else if (orientation.type === "portrait-secondary" || orientation.type === "portrait-primary") {
  console.log("Mmmh... you should rotate your device to landscape");
}
</pre>

<h2 id="規範">規範</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('Screen Orientation', '', 'Screen Orientation')}}</td>
   <td>{{Spec2('Screen Orientation')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="瀏覽器相容性">瀏覽器相容性</h2>

<p>{{CompatibilityTable}}</p>

<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>38</td>
   <td>{{CompatVersionUnknown}} {{property_prefix("moz")}}<sup>[1]</sup></td>
   <td>11{{property_prefix("ms")}}<sup>[2]</sup></td>
   <td>25</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for 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>{{CompatNo}}</td>
   <td>39</td>
   <td>{{CompatVersionUnknown}} {{property_prefix("moz")}}<sup>[1]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] This API is only implemented as a prefixed method (<code>mozOrientation</code>) in B2G and Firefox for Android.</p>

<p>[2] This API is implemented using a prefix (<code>msOrientation</code>) in Internet Explorer for Windows 8.1 and Windows RT 8.1. It is not supported on Windows 7.</p>

<h2 id="參見">參見</h2>

<ul>
 <li>{{domxref("Screen.orientation")}}</li>
 <li>{{domxref("Screen.unlockOrientation()")}}</li>
 <li>{{domxref("Screen.onorientationchange")}}</li>
 <li><a href="/zh-TW/docs/Web/API/CSS_Object_Model/Managing_screen_orientation">控制畫面方向</a></li>
</ul>