您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息

js如何获取鼠标当前位置实例

2024/3/29 9:07:06发布4次查看
本文主要和大家分享js如何获取鼠标当前位置实例,希望能帮助到大家。
<html> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312"/> <title>javascript获得鼠标位置</title> </head> <body> 鼠标x轴: <input id=xxx type=text> 鼠标y轴: <input id=yyy type=text> </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> </html>
相关推荐:
js代码实现鼠标拖拽div实例
js鼠标3次点击事件的实现代码
jquery实现鼠标滑过预览大图效果
以上就是js如何获取鼠标当前位置实例的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录