Window pageXOffset Property
- Προηγούμενη Σελίδα outerWidth
- Επόμενη Σελίδα pageYOffset
- Επιστροφή στο Πάνω επίπεδο Αντικείμενο Window
Definition and Usage
pageXOffset
The property returns the number of pixels the document has scrolled from the top left corner of the window.
pageXOffset
The property is equal to scrollX
Property.
pageXOffset
The property is read-only.
See also:
Instance
Example 1
Scroll the content by 100 pixels and prompt pageXOffset and pageYOffset:
window.scrollBy(100, 100); alert(window.pageXOffset + window.pageYOffset);
Example 2
Create a sticky navigation bar:
// Get the navigation bar const navbar = document.getElementById("navbar"); // Get the offset position of the navigation bar const sticky = navbar.offsetTop; // Add the sticky class to the navigation bar when you reach its scroll position. Remove the sticky class when you leave the scroll position. function myFunction() { if (window.pageYOffset >= sticky) { navbar.classList.add("sticky") } navbar.classList.remove("sticky"); } }
Syntax
window.pageXOffset
Or:
pageXOffset
Return value
Type | Description |
---|---|
Number | The number of pixels the document scrolls from the top left corner of the window. |
Browser support
Όλοι οι περιηγητές υποστηρίζουν window.pageXOffset
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Υποστήριξη | 9-11 | Υποστήριξη | Υποστήριξη | Υποστήριξη | Υποστήριξη |
- Προηγούμενη Σελίδα outerWidth
- Επόμενη Σελίδα pageYOffset
- Επιστροφή στο Πάνω επίπεδο Αντικείμενο Window