The jQuery Mousemove event provides real time X and Y coordinates of the mouse pointer. You can use it to find the current position of your mouse.
$(selector).mousemove(function (e) {
// code
});
I have a div element, so when I move my mouse over it then I should get the X and Y coordinates of the pointer.
To create this code I will use the .mousemove() event as shown below:
<div id="div1">Move Mouse Here</div>
$("#div1").mousemove(function (e) {
$(this).html("X coordinate: " + e.pageX + "<br>Y coordinate: " + e.pageY)
});
Download source codes:
1. Understanding the jQuery scrollTop Method with Examples
2. Multiple ways of using jQuery On Method – .on() – in your Website