WebGLRenderingContext: canvas プロパティ
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
WebGLRenderingContext.canvas プロパティは、コンテキストに関連付けられた HTMLCanvasElement または OffscreenCanvas オブジェクトへの読み取り専用の参照です。また、 <canvas> 要素や OffscreenCanvas オブジェクトに関連付けられていない場合、 null になる可能性があります。
構文
js
gl.canvas
返値
HTMLCanvasElement または OffscreenCanvas オブジェクトか、 null のいずれか。
例
>canvas 要素
この <canvas> 要素があるとします。
html
<canvas id="canvas"></canvas>
WebGLRenderingContext から canvas プロパティを使用して、参照を取得することができます。
js
const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
gl.canvas; // HTMLCanvasElement
オフスクリーンキャンバス
実験的な OffscreenCanvas オブジェクトを使用した例です。
js
const offscreen = new OffscreenCanvas(256, 256);
const gl = offscreen.getContext("webgl");
gl.canvas; // OffscreenCanvas
仕様書
| Specification |
|---|
| WebGL Specification> # DOM-WebGLRenderingContext-canvas> |
ブラウザーの互換性
Loading…