导航
×
   ❮   
HTML CSS JavaScript PHP Go Sass W3C Colors ECMS

HTML canvas isPointInPath() 方法


实例

如果点 20, 50 在当前路径中,则绘制一个矩形

您的浏览器不支持 HTML5 canvas 标签。

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

Copyright ©2020-2026 freew3c.com All Rights Reserved 提供的内容仅用于学习和测试,不保证内容的正确性。