Is there a way to ensure that an action is only executed when the user scrolls down vertically, and not when they scroll from end to start?
if( $(window).scrollTop() + $(window).height() == $(document).height() ) {
//do stuff
}
This is the code I have so far:
function addEvent( obj, type, fn ) {
if ( obj.attachEvent ) {
obj['e'+type+fn] = fn;
obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
obj.attachEvent( 'on'+type, obj[type+fn] );
} else
obj.addEventListener( type, fn, false );
}
addEvent(window, 'scroll', function(event) {
if( $(window).scrollTop() + $(window).height() == $(document).height() ) {
load();
}
});