1个回答
推荐于2016-05-01
展开全部
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://www.hsspw.com/hssc/JS/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function(){
$('#mo').mousemove(function(e){
n=$('#xxx').val()-50;
m=$('#yyy').val()-50;
$('#mo').css({top:m+'px', left:n+'px'});
});
});
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>
鼠标X轴:
<input id='xxx' type='text'>
鼠标Y轴:
<input id=yyy type=text>
<div id='mo' style='position:absolute;width:200px;height:200px;background:red'>111</div>
</body>
</html>
追问
这个感觉不是很灵活呢,鼠标移动到屏幕右端的时候,红色矩形区停留在了屏幕右端,
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询