Posted By

jofan on 01/07/11


Tagged


Versions (?)

Mouse position


 / Published in: JavaScript
 

  1. // From Quirksmode: http://www.quirksmode.org/js/events_properties.html
  2. function someEvent(e) {
  3. var posx = 0;
  4. var posy = 0;
  5. if (!e) var e = window.event;
  6. if (e.pageX || e.pageY) {
  7. posx = e.pageX;
  8. posy = e.pageY;
  9. }
  10. else if (e.clientX || e.clientY) {
  11. posx = e.clientX + document.body.scrollLeft
  12. + document.documentElement.scrollLeft;
  13. posy = e.clientY + document.body.scrollTop
  14. + document.documentElement.scrollTop;
  15. }
  16. // posx and posy contain the mouse position relative to the document
  17. // Do something with this information
  18. }

Report this snippet  

You need to login to post a comment.