OffscreenCanvas: clearElementGeometry() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Want more browser support for this feature? Tell us why.

The clearElementGeometry() method of the OffscreenCanvas interface clears any previous geometry applied to an ElementImage's underlying DOM presence.

Syntax

js
clearElementGeometry(element)

Parameters

element

A reference to an ElementImage.

Return value

None (undefined).

Description

The clearElementGeometry() method clears geometry applied to an ElementImage. This includes both geometry applied automatically by drawElementImage() calls, and geometry applied manually by updateElementGeometry() calls.

Calling clearElementGeometry() causes the referenced element image to be un-drawn, removing its interactivity and marking it as offscreen in the accessibility tree, without actually removing it from the DOM. You could re-draw it again with a subsequent updateElementGeometry() call.

It doesn't un-render the element from the <canvas> context; to do this, you'd have to redraw the canvas scene without rendering the element.

Examples

Clearing the geometry of an element image rendered via an offscreen canvas

In the following snippet we draw an element image to an offscreen 2D canvas context using drawElementImage(). We then clear the element image's geometry by calling clearElementGeometry() on the OffscreenCanvas:

js
OffscreenCtx.drawElementImage(img, x, y);

offscreen.clearElementGeometry(img);

See Canvas 2D context offscreen canvas example (source code) for a full offscreen canvas demo, and see drawElementImage() for a full example walkthrough.

Specifications

This feature does not appear to be defined in any specification.

Browser compatibility

See also