22

I need a way to automatically find the maximum bottom value of scrollTop, of the div id "#box".

Something like this: How to get maximum document scrolltop value

but just in a div, not the whole browser window. How can I do this?

Community
  • 1
  • 1
Jony Kale
  • 979
  • 3
  • 15
  • 35

4 Answers4

24

here you go:

var trueDivHeight = $('.someclass')[0].scrollHeight;
var divHeight = $('.someclass').height();
var scrollLeft = trueDivHeight - divHeight;
alert(scrollLeft);

Simplified

Neta Meta
  • 4,001
  • 9
  • 42
  • 67
18

Here's a version that accounts for padding and uses prop instead of accessing the DOM element directly.

$('#box').prop('scrollHeight') - $('#box').innerHeight();
Sean Fujiwara
  • 4,506
  • 22
  • 34
3

In vanilla JS:

var maxScrollTop = el.scrollHeight - el.offsetHeight
cronoklee
  • 6,482
  • 9
  • 52
  • 80
0

look here a complete answer:

https://stackoverflow.com/a/48246003/7668448

What about using that with jquery:

var max = $('#element')[0].scrollLeftMax; // when using the polyfill
var max =  $('#element')[0].scrollLeftMaxi(); // when using the other alternative more support IE6+
Mohamed Allal
  • 17,920
  • 5
  • 94
  • 97