Javascript Reference - Window pageXOffset and pageYOffset Property








The pageXOffset and pageYOffset properties returns scroll-offset in pixels from the upper left corner of the window.

Browser Support

pageXOffset and pageYOffset Yes 9.0 Yes Yes Yes

Syntax

window.pageXOffset
window.pageYOffset

Return Value

The number of pixels of the document scroll offset.





Example

The following code shows how to scroll the content by 100 pixels, and output the pageXOffset and pageYOffset.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()" style="position:fixed;">Click me to scroll</button><br><br>
<div style="border:1px solid black;background-color:lightblue;height:2000px;width:2000px;">
</div><!--from w  w w  .j  av a 2  s. com-->
<script>
function myFunction() {
    window.scrollBy(100, 100);
    console.log("pageXOffset: " + window.pageXOffset + ", pageYOffset: " + window.pageYOffset);
}
</script>

</body>
</html>

The code above is rendered as follows: