js與jquery中獲取當(dāng)前鼠標(biāo)的x、y坐標(biāo)位置的代碼
更新時間:2011年05月23日 21:44:56 作者:
jquery中獲取當(dāng)前鼠標(biāo)的x、y位置位置的代碼,需要的朋友可以參考下。
復(fù)制代碼 代碼如下:
<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獲取鼠標(biāo)當(dāng)前位置坐標(biāo)
鼠標(biāo)滑動顯示鼠標(biāo)的當(dāng)前位置坐標(biāo),主要是onmousemove函數(shù)。
復(fù)制代碼 代碼如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>javascript獲得鼠標(biāo)位置</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>
鼠標(biāo)X軸:
<input id=xxx type=text>
鼠標(biāo)Y軸:
<input id=yyy type=text>
</body>
相關(guān)文章
jQuery學(xué)習(xí)筆記之jQuery+CSS3的瀏覽器兼容性
這篇文章主要介紹了jQuery學(xué)習(xí)筆記之jQuery+CSS3的瀏覽器兼容性的相關(guān)資料,需要的朋友可以參考下2015-01-01jQuery 選擇同時包含兩個class的元素的實現(xiàn)方法
下面小編就為大家?guī)硪黄猨Query 選擇同時包含兩個class的元素的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06jquery刷新頁面的實現(xiàn)代碼(局部及全頁面刷新)
jquery刷新頁面的實現(xiàn)代碼(局部及全頁面刷新) ,需要的朋友可以參考下。2011-07-07jQuery實現(xiàn)仿美橙互聯(lián)兩級導(dǎo)航菜單效果完整實例
這篇文章主要介紹了jQuery實現(xiàn)仿美橙互聯(lián)兩級導(dǎo)航菜單效果,以完整實例形式分析了jQuery響應(yīng)鼠標(biāo)事件實現(xiàn)針對頁面元素的遍歷及樣式的動態(tài)操作技巧,需要的朋友可以參考下2015-09-09EasyUi tabs的高度與寬度根據(jù)IE窗口的變化自適應(yīng)代碼
EasyUi tabs的高度與寬度根據(jù)IE窗口的變化自適應(yīng)代碼,需要的朋友可以參考下。2010-10-10