js获取鼠标坐标
2012-12-09 13:55
260 查看
<!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=gb2312" />
<title>无标题文档</title>
<script>
function getPos(e,obj){
var e = e || window.event, x = e.clientX+document.documentElement.scrollLeft, y = e.clientY+document.documentElement.scrollTop;
var o = obj, xx=0, yy = 0;
while(o!=null){
xx += o.offsetLeft;
yy += o.offsetTop;
o = o.offsetParent;
}
return {x:x-xx, y:y-yy}
}
function visPos(e,obj,vis){
var pos = getPos(e, obj);
document.getElementById(vis).innerHTML = 'image_x:'+pos.x+'<br>image_y:'+pos.y;
}
</script>
</head>
<body>
<div style="width:2000px; height:2000px">
<div id="vis" style="width:200px; height:80px; position:absolute; left:50%; top:50%; margin-left:-100px; margin-top:-150px"></div>
<img src="http://bbs.blueidea.com/images/default/newtopic.gif" width="200" height="200"
onmousemove="visPos(event,this,'vis')" style="position:absolute; left:50%; top:50%; margin-left:-100px; margin-top:-100px"/>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
function getPos(e,obj){
var e = e || window.event, x = e.clientX+document.documentElement.scrollLeft, y = e.clientY+document.documentElement.scrollTop;
var o = obj, xx=0, yy = 0;
while(o!=null){
xx += o.offsetLeft;
yy += o.offsetTop;
o = o.offsetParent;
}
return {x:x-xx, y:y-yy}
}
function visPos(e,obj,vis){
var pos = getPos(e, obj);
document.getElementById(vis).innerHTML = 'image_x:'+pos.x+'<br>image_y:'+pos.y;
}
</script>
</head>
<body>
<div style="width:2000px; height:2000px">
<div id="vis" style="width:200px; height:80px; position:absolute; left:50%; top:50%; margin-left:-100px; margin-top:-150px"></div>
<img src="http://bbs.blueidea.com/images/default/newtopic.gif" width="200" height="200"
onmousemove="visPos(event,this,'vis')" style="position:absolute; left:50%; top:50%; margin-left:-100px; margin-top:-100px"/>
</div>
</body>
</html>
相关文章推荐
- 原生js获取鼠标X、Y轴坐标
- JS 获取 鼠标 坐标
- js获取鼠标坐标位置兼容多个浏览器
- js实时获取鼠标所在坐标
- js获取鼠标坐标
- js获取鼠标点击位置坐标
- JS获取鼠标坐标
- Js获取适时获取鼠标坐标值并显示
- 原生js获取鼠标坐标方法全面讲解:clientX/Y,pageX/Y,offsetX/Y,layerX/Y,screenX/Y
- js 火狐 iE 通用获取鼠标坐标,获取元素坐标
- JS获取鼠标坐标并且根据鼠标位置不同弹出不同内容
- 原生js获取鼠标坐标方法全面讲解:clientX/Y,pageX/Y,offsetX/Y,layerX/Y,screenX/Y
- js获取鼠标坐标,设置div的高度、位置、内容等,及注意要点
- 通过JS 获取Mouse Position(鼠标坐标)的代码
- js与jquery中获取当前鼠标的x、y坐标位置的代码
- js获取鼠标坐标实例
- JS网页在线获取鼠标坐标值的方法
- JS获取网页大小和鼠标当前坐标
- JS获取鼠标坐标代码
- js实时获取鼠标所在坐标