Canvas isPointInPath() 方法
示例
如果點 20, 50 在當前路徑中,則繪製一個矩形
JavaScript
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
ctx.rect(20, 20, 150, 100);
if (ctx.isPointInPath(20, 50)) {
ctx.stroke();
};
自己動手試一試 »
描述
isPointInPath() 方法返回指定的點是否在當前路徑中,如果存在則返回 true,否則返回 false。
JavaScript 語法 | context.isPointInPath(x, y); |
---|
引數值
引數 | 描述 |
---|---|
x | 要測試的 x 座標 |
y | 要測試的 y 座標 |
瀏覽器支援
<canvas>
元素是 HTML5 標準(2014)。
isPointInPath()
在所有現代瀏覽器中都受支援
Chrome | Edge | Firefox | Safari | Opera | IE |
是 | 是 | 是 | 是 | 是 | 9-11 |
❮ Canvas 參考