Get mouse coordinates relative to document


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.