我想检索鼠标指针上的点的x和y。我怎样才能做到这一点?回调总是关于点,我可能将光标放在自由区域上。
答案 0 :(得分:0)
我知道了
function getElementTop ( Elem )
{
var elem;
if ( document.getElementById )
{
elem = document.getElementById ( Elem );
}
else if ( document.all )
{
elem = document.all[Elem];
}
yPos = elem.offsetTop;
tempEl = elem.offsetParent;
while ( tempEl != null )
{
yPos += tempEl.offsetTop;
tempEl = tempEl.offsetParent;
}
return yPos;
}
function getElementLeft ( Elem )
{
var elem;
if ( document.getElementById )
{
var elem = document.getElementById ( Elem );
}
else if ( document.all )
{
var elem = document.all[Elem];
}
xPos = elem.offsetLeft;
tempEl = elem.offsetParent;
while ( tempEl != null )
{
xPos += tempEl.offsetLeft;
tempEl = tempEl.offsetParent;
}
return xPos;
}
var graphOnmousemove = function(arg,evt) {
console.log(evt);
var x = evt.pageX - getElementLeft("graph_data_div2");
var y = evt.pageY - getElementTop("graph_data_div2");
x = livePlotVtx2.toDataXCoord(x);
y = livePlotVtx2.toDataYCoord(y);
if (Ext.getCmp("graphTooltip") && Ext.getCmp("graphTooltip").body) {
Ext.getCmp("graphTooltip").body.dom.innerHTML = x.toFixed(2) + "," + y.toFixed(2);
Ext.getCmp("graphTooltip").show();
}
};
然后我将onmousemove事件添加到div onmousemove(this,event)