Copy codeThe Code is as follows:
<Div id = "testDiv"> put it on me </div>
<Script type = "text/javascript">
$ ('# TestDiv'). mousemove (function (e ){
Var xx = e. originalEvent. x | e. originalEvent. layerX | 0;
Var yy = e. originalEvent. y | e. originalEvent. layerY | 0;
$ (This). text (xx + '---' + yy );
});
</Script>
Javascript to get the coordinates of the current mouse position
Move the mouse to display the coordinates of the current mouse position, mainly the onmousemove function.
Copy codeThe Code is as follows:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> javascript to get the mouse position </title>
</Head>
<Body>
<Script>
Function mouseMove (ev)
{
Ev = ev | window. event;
Var mousePos = mouseCoords (ev );
Document. getElementById ("xxx"). value = mousePos. x;
Document. getElementById ("yyy"). value = mousePos. y;
}
Function mouseCoords (ev)
{
If (ev. pageX | ev. pageY ){
Return {x: ev. pageX, y: ev. pageY };
}
Return {
X: ev. clientX + document. body. scrollLeft-document. body. clientLeft,
Y: ev. clientY + document. body. scrollTop-document. body. clientTop
};
}
Document. onmousemove = mouseMove;
</Script>
Mouse X axis:
<Input id = xxx type = text>
Mouse Y axis:
<Input id = yyy type = text>
</Body>