WebGLRenderingContext.canvas
Свойство WebGLRenderingContext.canvas доступно только для чтения. Возвращает ссылку на объекты HTMLCanvasElement или OffscreenCanvas (en-US) связанные с установленным контекстом отрисовки. Если объект <canvas> или OffscreenCanvas (en-US) не связан с контекстом, то возвращается значение null.
Syntax
gl.canvas;
Return value
Either a HTMLCanvasElement or OffscreenCanvas (en-US) object or null.
Examples
Canvas element
Given this <canvas> element:
html
<canvas id="canvas"></canvas>
You can get back a reference to it from the WebGLRenderingContext using the canvas property:
js
var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
gl.canvas; // HTMLCanvasElement
Offscreen canvas
Example using the experimental OffscreenCanvas (en-US) object.
js
var offscreen = new OffscreenCanvas(256, 256);
var gl = offscreen.getContext('webgl');
gl.canvas; // OffscreenCanvas
Specifications
| Specification | Status | Comment |
|---|---|---|
| WebGL 1.0 Определение 'WebGLRenderingContext.canvas' в этой спецификации. |
Рекомендация | Initial definition. |
Browser compatibility
BCD tables only load in the browser