We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

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 初始定义

浏览器兼容性

No compatibility data found. Please contribute data for "api/WebGLRenderingContext" (depth: WebGLRenderingContext.canvas) to the MDN compatibility data repository.

另见

文档标签和贡献者

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