Three parts are used:
document.documentElement.scrollHeight //represents the total height of the page, including
undisplayed document.documentElement.clientHeight //represents the visible page height of the page
document.documentElement.scrollTop //represents the current page scroll height
Back to top:
document.body.scrollTop = document.documentElement.scrollTop = 0
Always keep the bottom:
document.documentElement.scrollTop =
document.documentElement.scrollHeight -
document.documentElement.clientHeight