<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<canvas id="canvas" width="500" height="500"></canvas>
<script type="text/javascript">
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
function drawRect(){
ctx.rect(100,100,50,50);
ctx.fillStyle = "palegreen";
ctx.fill();
ctx.beginPath();
ctx.rect(200,200,100,100);
ctx.fillStyle = "deeppink";
ctx.fill();
// 判断一个点是否在路径上
var a = ctx.isPointInPath(120,120);
console.log(a);
}
drawRect();
</script>
</body>
</html>