Skip to content
Advertisements

JavaScript Event pageX, pageY

The Event interface represents any event that occurs in the DOM; Some are generated by the user (such as mouse or keyboard events), others are produced by APIs (such as events that show whether an animation is working, videos are paused). There are many types of events, some of which use other interfaces based on the main Event interface. The event itself includes features and methods common to all events.

  • event.type: Returns the name of the event type when it is triggered.
  • event.currentTarget: The event listeners return the item that triggered the event.
  • event.target: Returns the element that triggered the event.
  • button: The read-only property indicates which mouse button is pressed to trigger the event.
  • The buttons: read-only property indicates which buttons are pressed on the mouse (or other input device) when the event is triggered.
  • event.timeStamp: Indicates the time that indicates when the event occurred.
  • event.clientX: Returns the horizontal coordinate of the mouse pointer over the current window when the mouse event is triggered.
  • event.clientY: Returns the vertical coordinate of the mouse pointer relative to the current window when the mouse event is triggered.
  • event.pageX:Returns the horizontal coordinate of the mouse pointer relative to the document when the mouse event is triggered.
  • event.pageY: Returns the vertical coordinate of the mouse pointer relative to the document when the mouse event is triggered
  • altKey: Returns whether the “ALT” key is pressed when a key event is triggered.
  • ctrlKey: Returns whether the “CTRL” key is pressed when a key event is triggered.
  • shiftKey: Returns whether the “SHIFT” key is pressed when a key event is triggered.

pageX, pageY

event.pageX: Returns the position of the mouse pointer relative to the document’s horizontal coordinate.
event.pageY: Returns the position of the mouse pointer relative to the document’s vertical coordinate.

Syntax:

event.pageX

event.pageY


pageX, pageY Example

example
<body>

    <div onmousemove="myFunction(event)" onmouseout="clear()"></div>
    <p id="show"></p>

    <script>

        function myFunction(e) {
            let cleintX = e.clientX;
            let clientY = e.clientY;
            let pageX = e.pageX;
            let pageY = e.pageY;
            let screenX = e.screenX;
            let screenY = e.screenY;
            let show = document.getElementById("show");
            show.innerHTML = "clientX: " + cleintX + "<br>" + "clientY: " + clientY + "<br>" +
                "pageX: " + pageX + "<br>" + "pageY: " + pageY + "<br>" +
                "screenX: " + screenX + "<br>" + "screeny: " + screenX;
        }

        function clear() {
            document.getElementById("show").innerHTML = "";
        }
        
    </script>

</body>
Advertisements

6 Comments »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: