我有拉斐尔纸,我想找到相对于我的纸张的坐标
我的html
:
<div style='width:100%;'>
<div id='mycanvas' class='canvas'></div>
</div>
我的Javascript
:
var mypaper = Raphael(mycanvas, '100%', '100%');
...
document.getElementById('mycanvas').onmouseover=function(event) {
var canvasPos = {
x: this.offsetLeft,
y: this.offsetTop
};
var coord = {
x: event.pageX-canvasPos.x,
y: event.pageY-canvasPos.y
};
};
我希望{* 1}}和coord.x
在论文的左上角为零,但不是
答案 0 :(得分:1)
最后,我找到了answer
function getCursorPosition(canvas, event) {
var rect = canvas.getBoundingClientRect();
var x = event.clientX - rect.left;
var y = event.clientY - rect.top;
console.log("x: " + x + " y: " + y);
}