HTML canvas isPointInPath() 方法

定義和用法

isPointInPath() 方法返回 true,如果指定的點位于當前路徑中;否則返回 false

實例

繪制一個矩形,如果點 20,50 位于當前路徑中:

Your browser does not support the HTML5 canvas tag.

JavaScript:

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

親自試一試

語法

context.isPointInPath(x,y);

參數值

參數 描述
x 測試的 x 坐標
y 測試的 y 坐標

瀏覽器支持

表中的數字注明了首個完全支持該屬性的瀏覽器版本。

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
4.0 9.0 3.6 4.0 10.1

注釋:Internet Explorer 8 以及更早的版本不支持 <canvas> 元素。