如何在指定的事件处理函数之外检索鼠标位置
例如,如果Event.MOUSEMOVE = somefuction
,我该怎么说...
someOtherFunction( maybeSomeParams )
{
getCurrentMouseLocn();
}
或
someOtherFunction( maybeSomeParams )
{
mouseXLocn = ?;
mouseYLocn = ?;
}
最佳答案
最简单的方法是捕获鼠标移动事件并将位置保存到全局变量中。
如果它已经被捕获,你可以这样做:
var oldFunction = document.onmousemove;
document.onmousemove = function(e)
{
// save x & y here...
return oldFunction(e);
}
关于javascript - 检索事件处理程序之外的鼠标位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/844187/