diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/document/visibilitystate | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/document/visibilitystate')
-rw-r--r-- | files/zh-cn/web/api/document/visibilitystate/index.html | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/document/visibilitystate/index.html b/files/zh-cn/web/api/document/visibilitystate/index.html new file mode 100644 index 0000000000..40cde7513b --- /dev/null +++ b/files/zh-cn/web/api/document/visibilitystate/index.html @@ -0,0 +1,52 @@ +--- +title: Document.visibilityState +slug: Web/API/Document/visibilityState +translation_of: Web/API/Document/visibilityState +--- +<p>{{ ApiRef("DOM") }}</p> + +<p> <code><strong>Document.visibilityState</strong></code> (只读属性), 返回{{domxref('document')}}的可见性, 即当前可见元素的上下文环境. 由此可以知道当前文档(即为页面)是在背后, 或是不可见的隐藏的标签页,或者(正在)预渲染.可用的值如下:</p> + +<ul> + <li><code>'visible'</code> : 此时页面内容至少是部分可见. 即此页面在前景标签页中,并且窗口没有最小化.</li> + <li><code>'hidden</code>' : 此时页面对用户不可见. 即文档处于背景标签页或者窗口处于最小化状态,或者操作系统正处于 '锁屏状态' .</li> + <li><code>'prerender'</code> : 页面此时正在渲染中, 因此是不可见的 (considered hidden for purposes of <code>document.hidden</code>). 文档只能从此状态开始,永远不能从其他值变为此状态.注意: 浏览器支持是可选的.</li> +</ul> + +<p>当此属性的值改变时, 会递交 {{event('visibilitychange')}} 事件给{{domxref("Document")}}.</p> + +<p>典型用法是防止当页面正在渲染时加载资源, 或者当页面在背景中或窗口最小化时禁止某些活动.</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox notranslate">var <em>string</em> = document.visibilityState</pre> + +<h2 id="示例">示例</h2> + +<pre class="brush:js; line-numbers language-js notranslate"><code class="language-js">document.addEventListener("visibilitychange", function() { + console.log( document.visibilityState ); + // Modify behavior... +});</code></pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th>Specification</th> + <th>Status</th> + <th>Comment</th> + </tr> + <tr> + <td>{{SpecName('Page Visibility API','#dom-document-visibilitystate', 'Document.visibilityState')}}</td> + <td>{{Spec2('Page Visibility API')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.Document.visibilityState")}}</p> |