HTML canvas isPointInPath() 方法

由网友 大卫 发布 阅读 6

HTML canvas isPointInPath() 方法

isPointInPath()是 Canvas 2D API 用于判断在当前路径中是否包含检测点的方法。

HTML canvas 参考手册

在线示例

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

您的浏览器,不支持HTML5 canvas标签.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML canvas isPointInPath()方法使用-大卫编程网(div.cn)</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 9、Firefox、Opera、Chrome 和 Safari 支持 isPointInPath() 方法。

注意:Internet Explorer 8 及之前的版本不支持 <canvas> 元素。

定义和用法

如果指定点在当前路径中,则isPointInPath()方法返回true,否则返回false

JavaScript 语法:context.isPointInPath(x,y);

参数值

参数描述
x要测试的 x 坐标。
y要测试的 y 坐标。
HTML canvas 参考手册

HTML canvas scale() 方法 HTML canvas quadraticCurveTo() 方法