`
wlhx
  • 浏览: 34875 次
  • 性别: Icon_minigender_1
  • 来自: 石家庄
社区版块
存档分类
最新评论

获取鼠标实时坐标

阅读更多
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css"> 
#top_div{ 
    position:absolute; 
	width:100PX;
	height:50px;
	border:1px solid #00F;
	text-align:center;
	color:blue;
} 
</style> 
<script type="text/javascript" src="jquery/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
function initMouseMove(){
document.onmousemove = function (e){
   x = document.documentElement.scrollLeft+e.clientX;
   y = document.documentElement.scrollTop+e.clientY; 
   $("#top_div").html("当前坐标 X:"+x+"Y:"+y);
   $("#top_div").css("left",x);
   $("#top_div").css("top",y);
}}

</script>
</head>
<body  onload="initMouseMove()">
<div id="top_div"></div> 
</body>
</html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics