Draw a rectangle if the point 20, 50 is in the current path:
<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="300" height="180" style="border:1px solid #d3d3d3;"> Your browser does not support the HTML5 canvas tag.</canvas> <script> var c = document.getElementById("myCanvas"); var ctx = c.getContext("2d"); ctx.rect(20, 20, 150, 100);// ww w .j av a 2 s.c om if (ctx.isPointInPath(20, 50)) { ctx.stroke(); }; </script> </body> </html>
The isPointInPath()
method returns true if the specified point is in the current path, otherwise false.
context.isPointInPath(x, y);
Parameter Values
Parameter | Description |
---|---|
x | The x-coordinate to test |
y | The y-coordinate to test |