因此,我用centerX和centerY获得了该点的中心,我想获得该点与鼠标之间的距离。
我收到一条错误消息,说clientX不起作用。
function dist(event){
var rect = canvas.getBoundingClientRect();
var mouseX = event.clientX - rect.left;
var mouseY = event.clientY - rect.top;
var a = centerX - mouseX;
var b = centerY - mouseY;
var dist = Math.hypot(a, b);
if(dist <= 50){
alert("test");
}
}