read scrolltop javascript code example
Example 1: javascript get scroll position
function getYPosition(){
var top = window.pageYOffset || document.documentElement.scrollTop
return top;
}
Example 2: html scroll div to top
var myDiv = document.getElementById('containerDiv');
myDiv.innerHTML = variableLongText;
myDiv.scrollTop = 0;