WebGLRenderingContext: canvas 属性
注意:此功能在 Web Workers 中可用。
WebGLRenderingContext.canvas 属性是一个只读引用,指向与该上下文关联的 或 HTMLCanvasElement 对象。如果它未与 OffscreenCanvas 元素或 <canvas> 对象关联,则可能为 OffscreenCanvas。null
值
或 HTMLCanvasElement 对象,或 OffscreenCanvas。null
示例
Canvas 元素
给定此 <canvas> 元素
html
<canvas id="canvas"></canvas>
您可以使用 canvas 属性从 WebGLRenderingContext 中获取对它的引用。
js
const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
gl.canvas; // HTMLCanvasElement
离屏 Canvas
使用实验性的 对象进行示例。OffscreenCanvas
js
const offscreen = new OffscreenCanvas(256, 256);
const gl = offscreen.getContext("webgl");
gl.canvas; // OffscreenCanvas
规范
| 规范 |
|---|
| WebGL 规范 # DOM-WebGLRenderingContext-canvas |
浏览器兼容性
加载中…