Posted By

micmath on 04/14/08


Tagged


Versions (?)

Get mouse coordinates relative to document


 / Published in: JavaScript
 

URL: http://evolt.org/article/Mission_Impossible_mouse_position/17/23335/index.html

Snagged from pp]{ It's relative to document, not the visible area in the window.

  1. function handleEvent(e)
  2. {
  3. if (!e) var e = window.event;
  4. var posx = 0;
  5. var posy = 0;
  6. if (!e) var e = window.event;
  7. if (e.pageX || e.pageY)
  8. {
  9. posx = e.pageX;
  10. posy = e.pageY;
  11. }
  12. else if (e.clientX || e.clientY)
  13. {
  14. posx = e.clientX + document.body.scrollLeft;
  15. posy = e.clientY + document.body.scrollTop;
  16. }
  17. // posx and posy contain
  18. // the mouse position relative to the document
  19. // Do something with this information
  20. }

Report this snippet  

You need to login to post a comment.