event.pageX
JQ Home <<
Objects <<
event.pageX
Event object document position (X-axis) property.
Description
The event.pageX
Event object property, contains the value of the mouse position relative to the left edge of the document (X-axis).
Syntax
Signature | Description |
---|---|
event.clientX | The value of the mouse position relative to the left edge of the document (X-axis). |
Parameters
None.
Return
A Number
object.
event.pageX
Example
Objects << Top
Contains the value of the mouse position relative to the left edge of the document (X-axis).
In the example below we show two new messages in the 'p' elements below every time the mouse moves over the image with the id of 'curry1'.
When the mouse moves while over the image, we trigger off the mousemove
JavaScript event on the 'image'. This then fires off the $('#curry1').mousemove(function(){})
code which outputs the messages.
$(function(){
$('#curry1').mousemove(function(event) {
var pageCoords = '(' + event.pageX + ', ' + event.pageY + ' )';
var viewableCoords = '(' + event.clientX + ', ' + event.clientY + ' )';
$('#animspan1').text('( event.pageX, event.pageY ) : ' + pageCoords);
$('#animspan2').text('( event.clientX, event.clientY ) : ' + viewableCoords);
});
$('#curry1').mousemove();
});
The page coordinates are:
The viewable page coordinates are:
Related Tutorials
jQuery Advanced Tutorials - Lesson 5 - The Event Object