HTML canvas isPointInPath() 方法
實例
如果點20,50 位於當前路徑中,則繪製一個矩形:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.rect(20,20,150,100);
if (ctx.isPointInPath(20,50))
{
ctx.stroke();
};
var ctx=c.getContext("2d");
ctx.rect(20,20,150,100);
if (ctx.isPointInPath(20,50))
{
ctx.stroke();
};
嘗試一下»
瀏覽器支持
Internet Explorer 9、Firefox、Opera、Chrome 和Safari 支持isPointInPath() 方法。
注意: Internet Explorer 8及之前的版本不支持<canvas>元素。
定義和用法
如果指定的點位於當前路徑中,isPointInPath() 方法返回true,否則返回false。
JavaScript 語法: | context.isPointInPath(x,y); |
---|
參數值
参数 | 描述 |
---|---|
x | 要测试的 x 坐标。 |
y | 要测试的 y 坐标。 |
HTML canvas參考手冊