English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
isPointInPath()는 Canvas 2D API 用于判断在当前路径中是否包含检测点的方法。
如果点 20,50 位于当前路径中,则绘制一个矩形:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>HTML canvas isPointInPath()方法使用-基础教程(oldtoolbag.com)</title> </head> <body> <canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3"> 您的浏览器不支持 HTML5 canvas 태그. </canvas> <script> var c = document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.rect(20,20,150,100); if (ctx.isPointInPath(20,50)) { ctx.stroke(); }; </script> </body> </html>테스트를 보세요 ‹/›
IEFirefoxOperaChromeSafari
Internet Explorer 9Firefox, Opera, Chrome, Safari 및 Safari가 isPointInPath()를 지원합니다 메서드.
주의:Internet Explorer 8 이전 버전은 <canvas> 요소를 지원하지 않습니다.
지정된 점이 현재 경로에 있으면 isPointInPath() 메서드가 true를 반환하고, 그렇지 않으면 false를 반환합니다
JavaScript 문법: | context.isPointInPath(x,y); |
---|
파라미터 | 설명 |
---|---|
x | 테스트할 x 좌표. |
y | 테스트할 y 좌표. |