Scroll
Call a function when the window is scrolled. For example, a function name onScroll
.
window.onscroll = function() {onScroll()};
Height
To get the full height of the document including what is visible when scrolling, use the highest value from these properties.
var scrollHeight = Math.max(
document.body.scrollHeight,
document.documentElement.scrollHeight,
document.body.offsetHeight,
document.documentElement.offsetHeight,
document.body.clientHeight,
document.documentElement.clientHeight
);
Position
For these functions, the coordinates are parameters (x,y)
.
window.scrollTo
Scroll to the absolute position.
For example, scroll to the top of the document.
window.scrollTo(0,0);
window.scrollBy
Scroll releative to the current position.
For example, scroll 100 pixels down from the current position.
window.scrollTo(0,100);
For these functions, the assumption is that the document is fully loaded and the
DOCTYPE
is set.