js 獲取坐標(biāo) 通過(guò)JS得到當(dāng)前焦點(diǎn)(鼠標(biāo))的坐標(biāo)屬性
更新時(shí)間:2013年01月04日 10:35:56 作者:
通過(guò)JS得到當(dāng)前焦點(diǎn)的坐標(biāo),如何實(shí)現(xiàn),接下來(lái)詳細(xì)介紹實(shí)現(xiàn)步驟,有需要的朋友可以參考下
通過(guò)JS得到當(dāng)前焦點(diǎn)的坐標(biāo)
如下是得到當(dāng)前焦點(diǎn)的坐標(biāo):
<!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" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
<meta name="auther" content="fq" />
<title>獲取鼠標(biāo)坐標(biāo)</title>
</head>
<body>
<script type="text/javascript">
function mousePosition(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
};
}
function mouseMove(ev){
ev = ev || window.event;
var mousePos = mousePosition(ev);
document.getElementById('xxx').value = mousePos.x;
document.getElementById('yyy').value = mousePos.y;
}
document.onmousemove = mouseMove;
</script>
X:<input id="xxx" type="text" /> Y:<input id="yyy" type="text" />
</body>
</html>
如下是得到當(dāng)前焦點(diǎn)的坐標(biāo):
復(fù)制代碼 代碼如下:
<!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" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
<meta name="auther" content="fq" />
<title>獲取鼠標(biāo)坐標(biāo)</title>
</head>
<body>
<script type="text/javascript">
function mousePosition(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
};
}
function mouseMove(ev){
ev = ev || window.event;
var mousePos = mousePosition(ev);
document.getElementById('xxx').value = mousePos.x;
document.getElementById('yyy').value = mousePos.y;
}
document.onmousemove = mouseMove;
</script>
X:<input id="xxx" type="text" /> Y:<input id="yyy" type="text" />
</body>
</html>
您可能感興趣的文章:
- js與jquery中獲取當(dāng)前鼠標(biāo)的x、y坐標(biāo)位置的代碼
- 基于JavaScript實(shí)現(xiàn) 獲取鼠標(biāo)點(diǎn)擊位置坐標(biāo)的方法
- JavaScript獲取鼠標(biāo)坐標(biāo)的函數(shù)(兼容IE、FireFox、Chrome)
- js獲得鼠標(biāo)的坐標(biāo)值的方法
- 通過(guò)百度地圖獲取公交線路的站點(diǎn)坐標(biāo)的js代碼
- javascript 事件對(duì)象 坐標(biāo)事件說(shuō)明
- js Event對(duì)象的5種坐標(biāo)
- 通過(guò)JS 獲取Mouse Position(鼠標(biāo)坐標(biāo))的代碼
- JavaScript獲取鼠標(biāo)移動(dòng)時(shí)的坐標(biāo)(兼容IE8、chome谷歌、Firefox)
- JavaScript實(shí)現(xiàn)二維坐標(biāo)點(diǎn)排序效果
相關(guān)文章
JavaScript自定義超時(shí)API代碼實(shí)例
這篇文章主要介紹了JavaScript自定義超時(shí)API代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-04-04
JS高級(jí)調(diào)試技巧:捕獲和分析 JavaScript Error詳解
前端工程師都知道 JavaScript 有基本的異常處理能力。我們可以 throw new Error(),瀏覽器也會(huì)在我們調(diào)用 API 出錯(cuò)時(shí)拋出異常。但估計(jì)絕大多數(shù)前端工程師都沒(méi)考慮過(guò)收集這些異常信息2014-03-03
原生JS+HTML5實(shí)現(xiàn)跟隨鼠標(biāo)一起流動(dòng)的粒子動(dòng)畫效果
這篇文章主要介紹了原生JS+HTML5實(shí)現(xiàn)跟隨鼠標(biāo)一起流動(dòng)的粒子動(dòng)畫效果,涉及javascript事件響應(yīng)、數(shù)值運(yùn)算及頁(yè)面元素屬性動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-05-05
詳解JavaScript添加給定的標(biāo)簽選項(xiàng)
這篇文章給大家分享了JavaScript實(shí)現(xiàn)添加給定的標(biāo)簽選項(xiàng)的相關(guān)知識(shí)點(diǎn)內(nèi)容以及代碼實(shí)例,有興趣的朋友們參考下。2018-09-09
深度剖析JavaScript作用域從局部到全局一網(wǎng)打盡
這篇文章主要為大家介紹了JavaScript作用域的深度剖析,從局部到全局一網(wǎng)打盡,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05
跟我學(xué)習(xí)javascript的定時(shí)器
跟我學(xué)習(xí)javascript的定時(shí)器,告訴大家具體的使用方法,并向大家提出了一個(gè)消息要求,制作一個(gè)定時(shí)器,有沒(méi)有朋友感興趣,挑戰(zhàn)一下2015-11-11
js中判斷兩個(gè)數(shù)組對(duì)象是否完全相等
這篇文章主要介紹了js中判斷兩個(gè)數(shù)組對(duì)象是否完全相等方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04

