标签:
两种方法:
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); }
标签:
原文地址:http://www.cnblogs.com/lunawzh/p/5185462.html