aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/webgl_lose_context/losecontext
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/webgl_lose_context/losecontext
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/webgl_lose_context/losecontext')
-rw-r--r--files/zh-cn/web/api/webgl_lose_context/losecontext/index.html66
1 files changed, 66 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/webgl_lose_context/losecontext/index.html b/files/zh-cn/web/api/webgl_lose_context/losecontext/index.html
new file mode 100644
index 0000000000..596b72ac30
--- /dev/null
+++ b/files/zh-cn/web/api/webgl_lose_context/losecontext/index.html
@@ -0,0 +1,66 @@
+---
+title: WEBGL_lose_context.loseContext()
+slug: Web/API/WEBGL_lose_context/loseContext
+tags:
+ - API
+ - Method
+ - Reference
+ - WebGL
+ - WebGL extension
+translation_of: Web/API/WEBGL_lose_context/loseContext
+---
+<div>{{APIRef("WebGL")}}</div>
+
+<p><strong>WEBGL_lose_context.loseContext()</strong>属于 <a href="/en-US/docs/Web/API/WebGL_API">WebGL API</a>, 一般用来模拟 {{domxref("WebGLRenderingContext")}} 的上下文丢失。</p>
+
+<p>这个方法会触发WebGL规范中上下文丢失的相关事件。通过这个方法丢失的上下文可以通过 {{domxref("WEBGL_lose_context.restoreContext()")}} 恢复。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">gl.getExtension('WEBGL_lose_context').loseContext();</pre>
+
+<h2 id="示例">示例</h2>
+
+<p>你可以用这个方法模拟 <code><a href="/en-US/docs/Web/API/HTMLCanvasElement/webglcontextlost_event">webglcontextlost</a></code> 事件:</p>
+
+<pre class="brush: js">var canvas = document.getElementById('canvas');
+var gl = canvas.getContext('webgl');
+
+canvas.addEventListener('webglcontextlost', function(e) {
+ console.log(e);
+}, false);
+
+gl.getExtension('WEBGL_lose_context').loseContext();
+
+// webglcontextlost事件被触发。
+</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('WEBGL_lose_context', "", "WEBGL_lose_context.loseContext")}}</td>
+ <td>{{Spec2('WEBGL_lose_context')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
+
+<p>{{Compat("api.WEBGL_lose_context.loseContext")}}</p>
+
+<h2 id="相关链接">相关链接</h2>
+
+<ul>
+ <li>{{domxref("WebGLRenderingContext.isContextLost()")}}</li>
+ <li>事件: <code><a href="/en-US/docs/Web/API/HTMLCanvasElement/webglcontextlost_event">webglcontextlost</a></code>, <code><a href="/en-US/docs/Web/API/HTMLCanvasElement/webglcontextrestored_event">webglcontextrestored</a></code>, <code><a href="/en-US/docs/Web/API/HTMLCanvasElement/webglcontextcreationerror_event">webglcontextcreationerror</a></code></li>
+</ul>