Skip to main content Accessibility Feedback

Distances

Unless otherwise noted, these work in all modern browsers, and IE9+. You can extend support back further with polyfills.

pageYOffset

Get the distance the user has scrolled from the top of the page.

var distance = window.pageYOffset;

Get an element’s distance from the top of the page

getOffsetTop() is a helper method I wrote to get an element’s distance from the top of the document.

var elem = document.querySelector('#some-element');
var distance = getOffsetTop(elem);