Posted By

devnull69 on 07/06/11


Tagged

mouse position


Versions (?)

Mouse position inside an element


 / Published in: JavaScript
 

  1. if(window.addEventListener) {
  2. element.addEventListener('mousemove', handleMouseClick, false);
  3. } else {
  4. element.attachEvent('onmousemove', handleMouseClick);
  5. }
  6.  
  7. function handleMouseClick(e) {
  8. if(window.event) e = window.event;
  9.  
  10. // mouse position relative to the top of the document
  11. var xpos = e.pageX - this.offsetLeft;
  12. var ypos = e.pageY - this.offsetTop;
  13.  
  14. // mouse position relative to the viewport
  15. //var xpos = e.clientX - this.offsetLeft;
  16. //var ypos = e.clientY - this.offsetTop;
  17. }

Report this snippet  

You need to login to post a comment.