ITeye博客

获取鼠标实时坐标

wlhx · 2013-08-15 20:35 · Jquery · Web前端 · Markdown

<!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>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。