How to get return value from mouse capturing function?
How to get return value from mouse capturing functi开发者_如何学Goon?
function getMousePosition(e)
{
positionX = e.pageX;
positionY = e.pageY;
if (positionX < 0){positionX = 0;}
if (positionY < 0){positionY = 0;}
return positionX + " " + positionY;
}
as in var mousePositions = getMousePosition(e);
function getMousePosition(e)
{
e = e || event //for cross browser implentation
var positionX = e.pageX;
var positionY = e.pageY;
if (positionX < 0){positionX = 0;}
if (positionY < 0){positionY = 0;}
return {positionX: positionX, positionY: positionY};
}
Now you can do this
var mousePositions = getMousePositions(someEventObject);
alert(mousePositions.positionX);
alert(mousePositions.positionY);
You have to assign the onmousemove Event-Listener to your function like in this expample:
document.onmousemove = getMousePosition();
精彩评论