Name

Canvas.getContext( ): return a context for drawing on the canvas

Synopsis

CanvasRenderingContext2D getContext(StringcontextID)

Arguments

contextID

This argument specifies the type of drawing you want to do with the canvas. Currently the only valid value is “2d”, which specifies two-dimensional drawing and causes this method to return a context object that exports a 2-D drawing API.

Returns

A CanvasRenderingContext2D object with which you can draw into the Canvas element.

Description

Returns a context representing the type of context to use in drawing. The intent is to provide different contexts for different drawing types (2-D, 3-D). Currently, the only one supported is “2d”, which returns a CanvasRenderingContext2D object that implements most of the methods used by a canvas.

See Also

CanvasRenderingContext2D

Get JavaScript: The Definitive Guide, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.