Detect mouse position in jQuery

To detect where the mouse was on the page we have to do is to read event object’s .pageX and .pageY properties.

$().mousemove(function(e){
   // e.pageX - gives you X position
   // e.pageY - gives you Y position
});
OR
jQuery(document).ready(function(){  
  $().mousemove(function(e){    
     mouseX = e.pageX;
     mouseY = e.pageY;  
 }); })
Share this nice post:

Leave a Reply

Your email address will not be published. Required fields are marked *