两种方法:

1.

cvs.onclick = function (e) {
    if (e.offsetX || e.layerX) {
           var x = e.offsetX == undefined ? e.layerX : e.offsetX;
           var y = e.offsetY == undefined ? e.layerY : e.offsetY;
   }
}

2.

 function windowToCanvas(x,y) {
      var cvsbox = cvs.getBoundingClientRect();
      return { x: Math.round(x - cvsbox.left), y: Math.round(y - cvsbox.top) };
}

cvs.onclick = function (e) {
     var clickXY = windowToCanvas(e.clientX, e.clientY);
}

 

相关文章:

  • 2022-12-23
  • 2021-04-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-17
  • 2022-12-23
  • 2021-04-05
猜你喜欢
  • 2021-04-21
  • 2022-12-23
  • 2021-08-29
  • 2021-10-15
  • 2022-02-06
  • 2022-12-23
  • 2021-07-26
相关资源
相似解决方案