Canvas isPointInPath() Method

❮ Canvas Reference

Example

Draw a rectangle if the point 20, 50 is in the current path:

YourbrowserdoesnotsupporttheHTML5canvastag.

JavaScript:

const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
ctx.rect(20, 20, 150, 100);
if (ctx.isPointInPath(20, 50)) {
 ctx.stroke();
};
Try it Yourself »

Description

The isPointInPath() method returns true if the specified point is in the current path, otherwise false.

JavaScript syntax: context.isPointInPath(x, y);

Parameter Values

Param Description
x The x-coordinate to test
y The y-coordinate to test

Browser Support

The <canvas> element is an HTML5 standard (2014).

isPointInPath() is supported in all modern browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes 9-11

❮ Canvas Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.