blob: 0578edbe08c606cf6ceb80fa1a173a9acf1a7758 (
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
|
---
title: orientationchange
slug: Web/API/Window/orientationchange_event
tags:
- API
- Event
- Window
- onorientationchange
- orientationchange
- 参考
- 方向
translation_of: Web/API/Window/orientationchange_event
---
<p><code>orientationchange</code>事件在<font><font>设备的纵横方向改变时触发。</font></font></p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Bubbles</th>
<td>No</td>
</tr>
<tr>
<th scope="row">Cancelable</th>
<td>No</td>
</tr>
<tr>
<th scope="row">Interface</th>
<td>{{domxref("Event")}}</td>
</tr>
<tr>
<th scope="row">Event handler</th>
<td>{{domxref("Window/onorientationchange", "onorientationchange")}}</td>
</tr>
</tbody>
</table>
<h2 id="示例">示例</h2>
<p>你可以在{{domxref("EventTarget/addEventListener", "addEventListener")}} 方法中使用 <code>orientationchange</code> 事件:</p>
<pre class="brush:js;">window.addEventListener("orientationchange", function() {
console.log("the orientation of the device is now " + screen.orientation.angle);
});
</pre>
<p>或者使用 {{domxref("Window/onorientationchange", "onorientationchange")}} 事件处理程序属性:</p>
<pre class="brush: js">window.onorientationchange = function() {
console.log("the orientation of the device is now " + screen.orientation.angle);
};</pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">规范</th>
<th scope="col">状态</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('Compat', '#event-orientationchange', 'orientationchange')}}</td>
<td>{{Spec2('Compat')}}</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("api.Window.orientationchange_event")}}</p>
|