Javascript examples for Canvas Reference:isPointInPath
The isPointInPath() method returns true if the point is in the current path, otherwise false.
context.isPointInPath(x, y);
Parameter | Description |
---|---|
x | The x-coordinate to test |
y | The y-coordinate to test |
Draw a rectangle if the point 20, 50 is in the current path:
<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="300" height="250" 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);/*from w w w.j a va2 s. c o m*/ if (ctx.isPointInPath(20, 50)) { ctx.stroke(); }; </script> </body> </html>