To detect if the scrollbar is all the way to the top:
var scrollY = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
if(scrollY == 0){ /* Scroll at top, do something here */ }
Infinite scroll implementation:
$(window).scroll(function(){
if(($(window).scrollTop() + 100) > ($(document).height() – $(window).height())){
/* You are 100px close to the bottom scroll, load more content or do something here */
Obviously, you will need Jquery. And the 100 magic number is the number of pixels you are away from the bottom of the screen.
You may also want to limit the checking for scrolls in your javascript for performance reasons, via setinterval, or settimeout. Otherwise you will be constantly hitting javascript as users scroll down. Details here:
https://github.com/shichuan/javascript-patterns/blob/master/jquery-patterns/window-scroll-event.html