在页面中 js 获取光标/鼠标的坐标,获取光标的的像素坐标
近期为网站开发页面统计,以前虽然也开发过,但是功能不是很全,所以这次把一些好功能给用上。
例如这次的,页面JS光标/鼠标坐标,你也许问着有什么用,百度统计中有个热点统计图,这下清楚明白了吧。
好了,上肉:
功能:获取光标的的像素坐标
<html> <head> <script type="text/javascript"> function showPosition(e){ var x,y; var e = e||window.event; document.getElementById("x").value = e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft; document.getElementById("y").value = e.clientY+document.body.scrollTop+document.documentElement.scrollTop } </script> </head> <body> <div onmousemove="showPosition(event);" > x:<input type="text" value="" /> y:<input type="text" value="" /> </div> </body> </html>
好肉来自:https://www.oschina.net/question/185906_71425
最后更新:2017-04-03 14:54:11