context.isPointInPath(x, y) 和想象中的不一样啊?

https://img2.mukewang.com/5bcae2e40001997b10670705.jpg

<!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上,奇怪啊,是哪里遗漏了什么吗?


繁花不似锦
浏览 457回答 1
1回答

慕虎7371278

没有遗漏,浏览器的问题,Chrome上有问题Safari上没事
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript