此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

WebGLContextEvent

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2016年9月.

* Some parts of this feature may have varying levels of support.

>

WebContextEvent 接口属于 WebGL API 的一部分,同时也是生成用来对 WebGL 渲染上下文作响应的事件接口。

继承

此接口从它的父接口 Event继承属性和方法。

Event WebGLContextEvent

属性

此接口从它的父接口 Event继承属性。

WebGLContextEvent.statusMessage

一个包含事件额外信息的只读属性。

方法

此接口本身并没有定义任何方法,而是从它的父接口 Event 继承方法。

示例

使用 WEBGL_lose_context 插件,你可以模拟 webglcontextlostwebglcontextrestored 事件:

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" 类型的 WebGLContextEvent 事件

规范

Specification
WebGL Specification>
# 5.15>

浏览器兼容性

相关内容