Posted By

1man on 02/14/08


Tagged

mouse cursor position


Versions (?)

Who likes this?

10 people have marked this snippet as a favorite

SpinZ
adix
joellevin
wizard04
donesmart
umang_nine
Knarf
masondixon
seanpowell
guo3823538


Cross Browser Cursor Position


 / Published in: JavaScript
 

URL: http://ajaxian.com/archives/javascript-tip-cross-browser-cursor-positioning

Nice little snippet i found on Ajaxian, finds the position of the mouse cursor when it is fired.

  1. function getPosition(e) {
  2. e = e || window.event;
  3. var cursor = {x:0, y:0};
  4. if (e.pageX || e.pageY) {
  5. cursor.x = e.pageX;
  6. cursor.y = e.pageY;
  7. }
  8. else {
  9. cursor.x = e.clientX +
  10. (document.documentElement.scrollLeft ||
  11. document.body.scrollLeft) -
  12. document.documentElement.clientLeft;
  13. cursor.y = e.clientY +
  14. (document.documentElement.scrollTop ||
  15. document.body.scrollTop) -
  16. document.documentElement.clientTop;
  17. }
  18. return cursor;
  19. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: adix on February 15, 2008

Interesting how you and Dustin Diaz made the exact same function, isn't it? http://www.dustindiaz.com/getelementsbyclass/

Posted By: adix on February 15, 2008

just ignore my comment, it was for another someone :D sorry

You need to login to post a comment.