clearRect method

Clears the pixels on a CanvasRenderingContext2D object within a given rectangle.

 

Syntax

object.clearRect(x, y, w, h);

Parameters

  • x [in]
    Type: number

    The x-coordinate, in pixels, of the upper-left corner of the rectangle in relation to the coordinates of the canvas.

  • y [in]
    Type: number

    The x-coordinate, in pixels, of the upper-left corner of the rectangle in relation to the coordinates of the canvas.

  • w [in]
    Type: number

    The width, in pixels, of the rectangle in relation to the coordinates of the canvas.

  • h [in]
    Type: number

    The height, in pixels, of the rectangle in relation to the coordinates of the canvas.

Return value

This method does not return a value.

Standards information

Remarks

The ICanvasRenderingContext2D::clearRect method clears the canvas to transparent black (that is, each pixel's RGBA value is equal to zero). To clear to a specific color, use the ICanvasRenderingContext2D::fillRect method.

See also

ICanvasRenderingContext2D::fillRect