-2

i'm trying to load more results when user scroll to the bottom of page. i want it to be as much as possible cross browser(dose not matter if it's jquery or js) it should support ie8 at least! right now for checking if user have scrolled to the bottom of page i use this code:

var sTop = document.body.scrollTop || document.documentElement.scrollTop || window.pageYOffset || 0;
if(sTop + window.outerHeight == document.body.clientHeight)  //user scrolled to bottom of the page?

but it's not cross browser.

the110boy
  • 71
  • 8
  • bad way of asking the question. "more results" is irrelevant. you need to ask "how to detect when scrolled to bottom of page" or something like that. – Marc B Sep 11 '15 at 21:41
  • possible duplicate of [Javascript: How to detect if browser window is scrolled to bottom?](http://stackoverflow.com/questions/9439725/javascript-how-to-detect-if-browser-window-is-scrolled-to-bottom) – Adam Buchanan Smith Sep 11 '15 at 21:50

1 Answers1

0
var currentBottom = $(window).scrollTop() + $(window).height();
var bodyHeight = $('body').height();
if (currentBottom >= bodyHeight) {
  console.log("Reached bottom");
}
Stephan Genyk
  • 177
  • 1
  • 6