aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/htmlcanvaselement/webglcontextlost_event/index.html
blob: bd8c206ab800fea81ec10a0e3e7d4d3bab061284 (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
---
title: 'HTMLCanvasElement: webglcontextlost event'
slug: Web/API/HTMLCanvasElement/webglcontextlost_event
translation_of: Web/API/HTMLCanvasElement/webglcontextlost_event
---
<div>{{APIRef}}</div>

<div></div>

<div>
<p>如果浏览器检测到与 {{domxref("WebGLRenderingContext")}}对象关联的图形缓冲区已丢失,则会触发<a href="/en-US/docs/Web/API/WebGL_API">WebGL API</a> 中的<code><strong>webglcontextlost</strong></code><strong> </strong>事件.</p>
</div>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row">冒泡</th>
   <td>Yes</td>
  </tr>
  <tr>
   <th scope="row">可取消</th>
   <td>Yes</td>
  </tr>
  <tr>
   <th scope="row">继承</th>
   <td>{{domxref("WebGLContextEvent")}}</td>
  </tr>
  <tr>
   <th scope="row">事件处理程序属性</th>
   <td>none</td>
  </tr>
 </tbody>
</table>

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

<p>{{domxref("WEBGL_lose_context")}} 扩展的帮助下,您可以模拟 <code>webglcontextlost</code> 事件:</p>

<pre class="brush: js">const canvas = document.getElementById('canvas');
const gl = canvas.getContext('webgl');

canvas.addEventListener('webglcontextlost', (event) =&gt; {
  console.log(event);
});

//WEBGL_lose_context是webgl是属于 WebGLAPI 的一个扩展API,它提供一组方法用来模拟一个 <code><a href="https://developer.mozilla.org/zh-CN/docs/Web/API/WebGLRenderingContext">W</a>ebGLRenderingContext</code> 上下文的丢失和恢复。
gl.getExtension('WEBGL_lose_context').loseContext();

// "webglcontextlost" event is logged.</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', '#5.15.2', 'webglcontextlost')}}</td>
   <td>{{Spec2('WebGL')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<div>


<p>{{Compat("api.HTMLCanvasElement.webglcontextlost_event")}}</p>
</div>

<h2 id="请参阅">请参阅</h2>

<ul>
 <li>{{domxref("WebGLContextEvent")}}</li>
 <li>{{domxref("WebGLRenderingContext.isContextLost()")}}</li>
 <li>{{domxref("WEBGL_lose_context")}}, {{domxref("WEBGL_lose_context.loseContext()")}}, {{domxref("WEBGL_lose_context.restoreContext()")}}</li>
</ul>