问题描述
<!DOCTYPE html><html><head>
<meta charset="UTF-8"> <title>Canvas: Point In Path</title>
</head><body>
<canvas id="canvas"></canvas> <script> var canvas = document.getElementById('canvas'); var context = canvas.getContext('2d'); canvas.width = 600; canvas.height = 400; context.fillStyle = "#efefef"; context.fillRect(0, 0, canvas.width, canvas.height); context.beginPath(); context.strokeStyle = "blue"; context.lineWidth = 3; context.moveTo(30, 30); context.lineTo(300, 300); context.stroke(); context.closePath(); console.log(context.isPointInPath(30, 30)); // true console.log(context.isPointInPath(100, 100)); // false console.log(context.isPointInPath(300, 300)); // true </script>
</body></html>
(100, 100)为什么判断不在path上,奇怪啊,是哪里遗漏了什么吗?
问题解答
回答1:没有遗漏,浏览器的问题,Chrome上有问题Safari上没事]