JS:相对于一个元素的鼠标坐标 [英] JS: mouse coordinates relative to an element
本文介绍了JS:相对于一个元素的鼠标坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它是跨浏览器捕捉鼠标坐标相对于一个div框与这样:
Is it cross-browser to catch the mouse coordinates relative to a div box with this:
pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById("thebox").offsetLeft;
pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById("thebox").offsetTop;
推荐答案
function dodoubleclick(e){
var mouseX, mouseY;
if(e.offsetX) {
mouseX = e.offsetX;
mouseY = e.offsetY;
}
else if(e.layerX) {
mouseX = e.layerX;
mouseY = e.layerY;
}
alert("mousex:"+mouseX+"and"+"mousey:"+mouseY);
}
鼠标坐标
这篇关于JS:相对于一个元素的鼠标坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文