MDN’s new design is in Beta! A sneak peek: https://blog.mozilla.org/opendesign/mdns-new-design-beta/

WebGLRenderingContext.canvas

WebGLRenderingContext.canvas 只读属性,对 HTMLCanvasElementOffscreenCanvas 对象的引用。如果绘图上下文没有相关联的 <canvas> 元素或 OffscreenCanvas 对象,值为 null

句法

gl.canvas;

返回值

HTMLCanvasElementOffscreenCanvasnull

示例

Canvas 元素

指定 <canvas> 元素:

<canvas id="canvas"></canvas>

你可以通过 canvas 得到一个从 WebGLRenderingContext 返回的引用:

var canvas = document.getElementById("canvas");
var gl = canvas.getContext("webgl");
gl.canvas; // HTMLCanvasElement

离屏Canvas

下面是一个使用试验阶段 OffscreenCanvas 对象的示例:

var offscreen = new OffscreenCanvas(256, 256);
var gl = offscreen.getContext("webgl");
gl.canvas; // OffscreenCanvas

规范

Specification Status Comment
WebGL 1.0
WebGLRenderingContext.canvas
Recommendation 初始定义

浏览器兼容性

Feature Chrome Edge Firefox Internet Explorer Opera Safari Servo
Basic Support91214.0111125.1No support
OffscreenCanvasNo supportNo supportNo support2No supportNo supportNo supportNo support
Feature Android Chrome for Android Edge Mobile Firefox for Android IE Mobile Opera Mobile Safari Mobile
Basic Support(Yes)25No support(Yes)111128.1
OffscreenCanvasNo supportNo supportNo supportNo support2No supportNo supportNo support

1. To access the WebGL context, use experimental-webgl rather than the standard webgl

2. This feature is experimentally implemented since Firefox 44; to activate it, in about:config, set gfx.offscreencanvas.enabled to true

另见

文档标签和贡献者

 此页面的贡献者: luojia, LiebeU
 最后编辑者: luojia,