Home >Web Front-end >JS Tutorial >Code to obtain the x, y coordinate position of the current mouse in js and jquery_jquery

Code to obtain the x, y coordinate position of the current mouse in js and jquery_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 18:06:36992browse
Copy code The code is as follows:

Put it above me< ;/div>


javascript gets the current position coordinates of the mouse
Mouse sliding displays the current position coordinates of the mouse, mainly onmousemove function.
Copy code The code is as follows:




javascript gets mouse position


<script> <br>function mouseMove(ev) <br>{ <br>Ev= ev || window.event; <br>var mousePos = mouseCoords(ev) ; <br>document.getElementById("xxx").value = mousePos.x; <br>document.getElementById("yyy").value = mousePos.y; <br>} <br>function mouseCoords(ev) <br>{ <br>if(ev.pageX || ev.pageY){ <br>return {x:ev.pageX, y:ev.pageY}; <br>} <br>return{ <br>x: ev.clientX document.body.scrollLeft - document.body.clientLeft, <br>y:ev.clientY document.body.scrollTop - document.body.clientTop <br>}; <br>} <br>document.onmousemove = mouseMove; <br></script>
Mouse X axis:

Mouse Y axis:


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn