Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY CYBERSECURITY DATA SCIENCE
     ❯   

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