For JavaScript to obtain the current mouse coordinates, you have to understand the coordinates of different browsers. The specific code is as follows:
code is as follows: <html>
<head>
<title>javascript get current mouse coordinates </title>
<meta http-equiv= "Content-type" content= text/html;charset=utf-8 "/>"
<script type= "Text/javascript" >
function mouseposition (EV) {
if (Ev.pagex | | ev.pagey) {//FIREFOX, chrome etc browser
return {x:ev.pagex,y:ev.pagey};
}
return {//IE browser
X:ev.clientx + document.body.scrollleft-document.body.clientleft,
Y:ev.clienty + document.body.scrolltop-document.body.clienttop
};
}
function MouseMove (EV) {
ev = EV | | window.event;
var mousepos = mouseposition (EV);
document.getElementById (' x '). InnerHTML = mousepos.x;
document.getElementById (' y '). InnerHTML = Mousepos.y;
}
document.onmousemove = MouseMove;
</script>
<style type= "Text/css" >
H3{color:blue;}
p{line-height:30px;height:30px;font-size:14px;width:500px;}
Span{color:orange;font-weight:bold;}
</style>
</head>
<body>
<h3> your mouse has been tracked </h3>
<p> X-axis coordinates: <span id= "x" ></span></p>
<p> y axis coordinates: <span id= "y" ></span></p>
</body>
</html>