aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/document/onfullscreenchange/index.html
blob: e012de078fc7f718cc82143ab13fff1893ffa500 (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
---
title: Document.onfullscreenchange
slug: Web/API/Document/onfullscreenchange
tags:
  - API
  - Document
  - onfullscreenchange
translation_of: Web/API/Document/onfullscreenchange
---
<div>{{ApiRef("Fullscreen API")}}</div>

<p>{{domxref("Document")}}接口的<strong><code>onfullscreenchange</code> </strong>属性是 {{event("fullscreenchange")}} 事件的处理器,该处理器在文档进入或者退出全屏模式的时候立即触发。</p>

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

<pre class="syntaxbox notranslate"><var>targetDocument</var>.onfullscreenchange = <var>fullscreenChangeHandler</var>;
</pre>

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

<p>每当文档接收到{{event("fullscreenchange")}} 事件时都会调用该事件处理程序,它表明文档正在进入或退出全屏模式。</p>

<h2 id="使用说明">使用说明</h2>

<p><code>fullscreenchange</code>事件不会直接说明文档当前是进入还是退出全屏模式,因此你的事件处理程序应查看{{domxref("Document.fullscreenElement")}}的值。 如果为null,则该事件表示已退出全屏模式; 否则,指定的元素将接管屏幕。</p>

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

<pre class="brush: js notranslate">document.onfullscreenchange = function ( event ) {
  console.log("FULL SCREEN CHANGE")
};
document.documentElement.onclick = function () {
  // requestFullscreen() 方法必须在一个事件处理器的方法体里执行,否则将会失败
  document.documentElement.requestFullscreen();
}
</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName("Fullscreen", "#handler-document-onfullscreenchange", "onfullscreenchange")}}</td>
   <td>{{Spec2("HTML WHATWG")}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{Compat("api.Document.onfullscreenchange")}}</p>

<h2 id="相关文章">相关文章</h2>

<ul>
 <li><a href="/zh-CN/docs/Web/API/Fullscreen_API">Fullscreen API</a></li>
 <li><a href="/zh-CN/docs/Web/API/Fullscreen_API/Guide">Guide to the Fullscreen API</a></li>
 <li>{{event("fullscreenchange")}}</li>
 <li>{{domxref("Document.onfullscreenerror")}}</li>
</ul>