Posted By

hasantayyar on 07/06/09


Tagged

javascript jquery mouse position


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

vali29


Identifying & locating mouse position in jQuery


 / Published in: jQuery
 

URL: http://jquery-howto.blogspot.com/2009/07/identifying-locating-mouse-position-in.html

  1. $("#someDiv").click(function(e){
  2. var relativeX = e.pageX - this.offsetLeft;
  3. var relativeY = e.pageY - this.offsetTop;
  4. });

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: delikassap on October 13, 2010

function doSomething(e) { var posx = 0; var posy = 0; if (!e) var e = window.event; if (e.pageX || e.pageY) { posx = e.pageX; posy = e.pageY; } else if (e.clientX || e.clientY) { posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; } // posx and posy contain the mouse position relative to the document // Do something with this information }

taken from : http://www.quirksmode.org/js/events_properties.html

You need to login to post a comment.