Get the current scroll

DOM elements have their current scroll state in elem.scrollLeft/scrollTop.
For document scroll document.documentElement.scrollLeft/Top works in most browsers, except older WebKit-based ones, like Safari (bug 5991), where we should use document.body instead of document.documentElement.
Luckily, we don’t have to remember these peculiarities at all, because the scroll is available in the special properties window.pageXOffset/pageYOffset:

  1. alert('Current scroll from the top: ' + window.pageYOffset);
  2. alert('Current scroll from the left: ' + window.pageXOffset);