Getting the Current Location in the Web Page

window.pageXOffset; // number of pixels the page has scrolled to the right window.pageYOffset; // returns number of pixels the page has scrolled down

When writing dynamic code, it is often necessary to determine the exact location in the web page that is currently being viewed. When the user scrolls down or to the right, the position of the page to the frame of the browser view port changes.

To determine the number of pixels the page has scrolled to the right, use the window.pageXOffset attribute. To determine the number of pixels the page has scrolled down, use the window.pageYOffset attribute.

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.