Checking Is Near/at The Bottom Of The Page
I need to check if an element is x pixels from the bottom of the page, to dynamically load new content. currently, scrollTop and height do not match even if the bar is on the botto
Solution 1:
You may want to try the following (tested in Firefox 3.5 and IE 8 only):
functionpollScrollPosition() {
var y = (document.all) ? document.body.scrollTop : window.pageYOffset;
var max = window.scrollMaxY ||
(document.body.scrollHeight - document.body.clientHeight);
if ((max - y) < 100) {
console.log('Within the bottom 100 pixels. Do Something!');
}
}
// Check the scroll position every 250mssetInterval(pollScrollPosition, 250);
Screenshot from the above example in Firebug:
Post a Comment for "Checking Is Near/at The Bottom Of The Page"