Cross-browser method for detecting the scrollTop of the browser window
Solution 1:
function getScrollTop(){
if(typeof pageYOffset!= 'undefined'){
//most browsers except IE before #9
return pageYOffset;
}
else{
var B= document.body; //IE 'quirks'
var D= document.documentElement; //IE with doctype
D= (D.clientHeight)? D: B;
return D.scrollTop;
}
}
alert(getScrollTop())
Solution 2:
Or just simple as:
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;