/ Published in: JavaScript

Nice little snippet i found on Ajaxian, finds the position of the mouse cursor when it is fired.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function getPosition(e) { e = e || window.event; var cursor = {x:0, y:0}; if (e.pageX || e.pageY) { cursor.x = e.pageX; cursor.y = e.pageY; } else { cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft; cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop; } return cursor; }
URL: http://ajaxian.com/archives/javascript-tip-cross-browser-cursor-positioning
Comments
