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 July 2015.
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 |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
canvas |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.