English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
isPointInPath()是 Canvas 2D API 用于判断在当前路径中是否包含检测点的方法。
Manual de referência do canvas HTML
如果点 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>Teste e veja ‹/›
IEFirefoxOperaChromeSafari
Internet Explorer 9e Firefox, Opera, Chrome e Safari suportam isPointInPath() Método.
Atenção:Internet Explorer 8 Versões anteriores a e não suportam o elemento <canvas>.
Se o ponto especificado estiver na trajetória atual, o método isPointInPath() retorna true, caso contrário, retorna false
Sintaxe JavaScript: | context.isPointInPath(x,y); |
---|
Parâmetro | Descrição |
---|---|
x | Coordenada x a ser testada. |
y | Coordenada y a ser testada. |