Determine mouse position outside of events (using jQuery)?

Not possible. You can however use the same approach in the tutorial to store the position in a global variable and read it outside the event.

Like this:

jQuery(document).ready(function(){
   $().mousemove(function(e){
      window.mouseXPos = e.pageX;
      window.mouseYPos = e.pageY;
   }); 
})

You can now use window.mouseXPos and window.mouseYPos from anywhere.

Leave a Comment