jQuery Tutorial
event.pageX event.pageY
event.pageX and even.pageY properties are used to get the positions of the mouse pointer relative to the left and top edge of the document respectively when mouse is moving.
<html> <head> <title>The jQuery Example</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script type = "text/javascript"> $(document).ready(function() { $(document).mousemove(function(event) { var x = event.pageX; var y = event.pageY; $('span').text("Current position X: " + x+ ", Current position Y: "+y); $('span').css('color', 'blue'); }); }); </script> </head> <body> <p>Test Section</p> <p>Please click any where in the page to get the mouse position X and Y: <span></span></p> </body> </html>Output:
event.pageX - returns the X coordinate relative to the left edge of the document.
event.pageY - returns the Y coordinate relative to the top edge of the document.
« Previous Next »jQuery Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page