Skip to content

Documentation / @ripl/canvas / createContext

Function: createContext()

createContext(target, options?): CanvasContext

Defined in: canvas/src/context.ts:458

Creates a Canvas 2D rendering context (a concrete Context) attached to the given DOM target.

Parameters

ParameterTypeDescription
targetstring | HTMLElementA DOM element or CSS selector identifying the element to mount the canvas into.
options?ContextOptions<Record<string, unknown>>Optional context configuration such as interactivity and metadata.

Returns

CanvasContext

The constructed CanvasContext.

Example

ts
const context = createContext(target);