--- title: HTMLCanvasElement.transferControlToOffscreen() slug: Web/API/HTMLCanvasElement/transferControlToOffscreen tags: - Canvas - Web图形技术 - 离屏Canvas translation_of: Web/API/HTMLCanvasElement/transferControlToOffscreen ---
{{APIRef("Canvas API")}} {{SeeCompatTable}}

方法 HTMLCanvasElement.transferControlToOffscreen() 将控制转移到一个在主线程或者web worker的 {{domxref("OffscreenCanvas")}} 对象上。

用法

OffscreenCanvas HTMLCanvasElement.transferControlToOffscreen()

返回值

一个 {{domxref("OffscreenCanvas")}} 对象。

样例

var htmlCanvas = document.createElement('canvas');
var offscreen = htmlCanvas.transferControlToOffscreen();
var gl = offscreen.getContext('webgl');

// ... some drawing using the gl context ...

// Push frames back to the original HTMLCanvasElement
gl.commit();

规范

Specification Status Comment
{{SpecName('HTML WHATWG', "canvas.html#dom-canvas-transfercontroltooffscreen", "HTMLCanvasElement.transferControlToOffscreen()")}} {{Spec2('HTML WHATWG')}}

浏览器兼容性

{{Compat("api.HTMLCanvasElement.transferControlToOffscreen")}}

查阅