I wish to achieve content load when the user scrolls to the bottom of the page.
I am having a problem. It works fine on desktop browsers but not on mobile. I have imple
An improved jQuery version of the code
var scrollRefresh = {
pastTop: false,
pastBottom: false,
previous: 0,
bottom: function(callback) {
var pBottom = $(window).height() + $(window).scrollTop() >= $(document).height();
if(!this.pastBottom && pBottom) {
callback($(window).height() + $(window).scrollTop());
this.pastBottom = true;
} else {
if(!pBottom) this.pastBottom = false;
}
this.previous = $(window).scrollTop();
},
top: function(callback) {
var pTop = $(window).scrollTop() < this.scrollPrevious && $(window).scrollTop <= 0;
if(!this.pastTop && pTop) {
callback($(window).scrollTop());
this.pastTop = true;
} else {
if(!pTop) this.pastTop = false;
}
this.previous = $(window).scrollTop();
}
}
$(window).scroll(function() {
scrollRefresh.top(function(pos) {
console.log("Loading top. " + pos);
alert("scrolled to top"); //You should delete this line
});
scrollRefresh.bottom(function(pos) {
console.log("Loading bottom. " + pos);
alert("scrolled to bottom"); //You should delete this line
});
});