WebGLContextEvent

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

继承

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

属性

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

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

方法

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

示例

使用 WEBGL_lose_context 插件, 你可以模拟 webglcontextlost 和 webglcontextrestored 事件:

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 事件

规范

规范 状态 注释
WebGL 1.0
WebGLContextEvent
Recommendation Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
WebGLContextEventChrome Full support 9Edge Full support 12Firefox Full support 49IE Full support 11Opera Full support 12Safari Full support 5.1WebView Android Full support YesChrome Android Full support 25Firefox Android Full support 49Opera Android Full support 12Safari iOS Full support 8.1Samsung Internet Android Full support Yes
statusMessageChrome Full support 9Edge Full support 12Firefox Full support 49IE Full support 11Opera Full support 12Safari Full support 5.1WebView Android Full support YesChrome Android Full support 25Firefox Android Full support 49Opera Android Full support 12Safari iOS Full support 8.1Samsung Internet Android Full support Yes
Available in workers
Experimental
Chrome No support NoEdge No support NoFirefox Full support 49
Disabled
Full support 49
Disabled
Disabled From version 49: this feature is behind the gfx.offscreencanvas.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android No support No

Legend

Full support  
Full support
No support  
No support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
User must explicitly enable this feature.
User must explicitly enable this feature.

相关内容