canvas中坐标处理
2017-08-08 本文已影响0人
JeremyChi
代码
function windowTocanvas(canvas, x, y) {
var bbox = canvas.getBoundingClientRect();
return {
x: x - bbox.left * (canvas.width / bbox.width),
y: y - bbox.top * (canvas.height / bbox.height)
};
}
// 其中x为clientX y为clientY