--- title: CanvasRenderingContext2D.isPointInPath() slug: Web/API/CanvasRenderingContext2D/isPointInPath translation_of: Web/API/CanvasRenderingContext2D/isPointInPath ---
CanvasRenderingContext2D
.isPointInPath()
是 Canvas 2D API 用于判断在当前路径中是否包含检测点的方法。
boolean ctx.isPointInPath(x, y); boolean ctx.isPointInPath(x, y, fillRule); boolean ctx.isPointInPath(path, x, y); boolean ctx.isPointInPath(path, x, y, fillRule);
fillRule
path
isPointInPath
方法这是一段简单的代码片段,使用 isPointinPath
方法检查某点是否在当前的路径内。
<canvas id="canvas"></canvas>
var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); ctx.rect(10, 10, 100, 100); ctx.stroke(); console.log(ctx.isPointInPath(10, 10)); // true
修改下面的代码, 在线查看 canvas的变化并在你的 控制台 中观察日志信息:
{{ EmbedLiveSample('Playable_code', 700, 360) }}
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', "scripting.html#dom-context-2d-ispointinpath", "CanvasRenderingContext2D.isPointInPath")}} | {{Spec2('HTML WHATWG')}} |
{{ CompatibilityTable() }}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} |
Path parameter | {{ CompatVersionUnknown() }} | {{ CompatGeckoDesktop(31) }} | {{ CompatNo }} | {{ CompatVersionUnknown() }} | {{ CompatNo }} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} |
Path parameter | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatGeckoMobile(31) }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} |