0

According to the first answer to the question at Stackoverflow, it can be known when element.innerHeight + element.scrollTop is greater than or equal to element.offsetHeight. Shouldn't it be element.innerHeight + element.scrollTop is greater than or equal to element.scrollHeight? offsetHeight just includes the padding while calculating the visible height, what we want here is to find whether the scrolled height plus the visible height equals the total height, isn't the total height given by scrollHeight?

Community
  • 1
  • 1
SexyBeast
  • 7,913
  • 28
  • 108
  • 196

1 Answers1

1

In general, yes. However, that question is about the page specifically, and the <body> element doesn't actually scroll; the viewport does.

Try it out: make sure this page scrolls, then open a console:

> document.body.offsetHeight === document.body.scrollHeight
true
Ry-
  • 218,210
  • 55
  • 464
  • 476
  • Oh, ok. So surely that code won't work for normal page elements? – SexyBeast Jul 26 '12 at 15:58
  • Any idea about the browser support of `scrollTop` and `scrollHeight` properties? Do they work in IE 5+? I have Googled extensively, couldn't find convenient answers! – SexyBeast Jul 26 '12 at 16:01
  • 1
    @Cupidvogel: Nope, I can't find any information either, and I don't have IE6 or lower to test with. But it works on any reasonably modern browser. – Ry- Jul 26 '12 at 16:07
  • Yeah I know that would work with Javascript, wanted to know how to make it work without. Surely there has to be a solution (it's a pretty big bug, you can't design fixed-height elements without Javascript!), somehow it is eluding Google! – SexyBeast Jul 26 '12 at 16:13
  • @Cupidvogel: What do you mean by fixed-height elements? I thought this question was about detecting when the user scrolls an element to the bottom... – Ry- Jul 26 '12 at 16:21
  • Oh sorry, I was simultaneously answering two questions, posted the right comment in the wrong place! :( – SexyBeast Jul 26 '12 at 17:07