js与jquery中获取当前鼠标的x、y坐标位置的代码
更新时间:2011年05月23日 21:44:56 作者:
jquery中获取当前鼠标的x、y位置位置的代码,需要的朋友可以参考下。
复制代码 代码如下:
<div id="testDiv">放在我上面</div>
<script type="text/javascript">
$('#testDiv').mousemove(function(e) {
var xx = e.originalEvent.x || e.originalEvent.layerX || 0;
var yy = e.originalEvent.y || e.originalEvent.layerY || 0;
$(this).text(xx + '---' + yy);
});
</script>
javascript获取鼠标当前位置坐标
鼠标滑动显示鼠标的当前位置坐标,主要是onmousemove函数。
复制代码 代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>javascript获得鼠标位置</title>
</head>
<body>
<script>
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>
</body>
相关文章
使用CDN和AJAX加速WordPress中jQuery的加载
这篇文章主要介绍了使用CDN和AJAX加速WordPress中jQuery的加载的方法,注意一下WordPress中以及CDN的Google连接在内地的网络问题,需要的朋友可以参考下2015-12-12
两种方法解决javascript url post 特殊字符转义 + & #
本文主要介绍javascript使用url传值的时候数据丢失的问题,希望对大家有所帮助。2016-04-04
Jquery遍历筛选数组的几种方法和遍历解析json对象,Map()方法详解以及数组中查询某值是否存在
今天小编就为大家分享一篇关于Jquery遍历筛选数组的几种方法和遍历解析json对象|Map()方法详解以及数组中查询某值是否存在,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧2019-01-01


最新评论