OffscreenCanvas: contextrestored イベント
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
contextrestored は OffscreenCanvas インターフェイスのイベントで、ブラウザーが前回失われた OffscreenCanvasRenderingContext2D コンテキストを復元した場合に発行されます。
このイベントを受信した後、コンテキストの状態を再描画、リソースの再取得、および再初期化することができます。
構文
このイベント名を addEventListener() などのメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。
js
addEventListener("contextrestored", (event) => { })
oncontextrestored = (event) => { }
イベント型
一般的な Event です。
例
以下のコード断片は、コンテキストの復元イベントを検出します。
js
const canvas = new OffscreenCanvas(256, 256);
const gl = offscreen.getContext("2d");
canvas.addEventListener(
"contextrestored",
(e) => {
console.log(e);
// redrawCanvas() 等を呼び出す
},
false,
);
仕様書
| Specification |
|---|
| HTML> # event-contextrestored> |
| HTML> # handler-offscreencanvas-oncontextrestored> |
ブラウザーの互換性
Loading…