javascript - context.isPointInPath(x, y) 和想象中的不一样啊?
本文介绍了javascript - context.isPointInPath(x, y) 和想象中的不一样啊?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
<!DOCTYPE html>
<html lang="en">
<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上,奇怪啊,是哪里遗漏了什么吗?
解决方案
没有遗漏,浏览器的问题,Chrome上有问题Safari上没事
这篇关于javascript - context.isPointInPath(x, y) 和想象中的不一样啊?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文