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
上一篇 下一篇

猜你喜欢

热点阅读