// 代码省略了部分,这里已经得到了图形了,已经画出来了 ctx.fillStyle = "rgb(200,0,0)"; ctx.fillRect (10, 10, 55, 50); // 为什么这里是false呢? console.log(ctx.isPointInPath(40, 40));
因为你并没有绘制 path,只是用颜色填充区域而已。 你试试这个: ctx.moveTo(10,10); ctx.lineTo(65,10); ctx.lineTo(65,60); ctx.lineTo(10,60); ctx.lineTo(10,10); ctx.stroke(); ctx.fillStyle = "rgb(200,0,0)"; ctx.fillRect (10, 10, 55, 50); 此时返回的是 true。 参考:isPointInPath()
因为你并没有绘制
path
,只是用颜色填充区域而已。你试试这个:
此时返回的是
true
。参考:isPointInPath()