HTML canvas isPointInPath()Method

HTML canvas 参考手册HTML canvas Reference Manual

Example

If point 20,50 is in the current path, draw a rectangle:

YourbrowserdoesnotsupporttheHTML5canvastag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.rect(20,20,150,100);
if (ctx.isPointInPath(20,50))
   {
   ctx.stroke();
   };

Try it Yourself »

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Internet Explorer 9, Firefox, Opera, Chrome, and Safari support the isPointInPath() method.

Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.


Definition and Usage

If the specified point is in the current path, the isPointInPath() method returns true; otherwise, it returns false.

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

Parameter Values

Parameter Description
x The x-coordinate to test.
y The y-coordinate to test.


HTML canvas 参考手册HTML canvas Reference Manual Other Extensions