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
  • 3,848
  • 9
  • 40
  • 66
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,493
  • 21
  • 34
2

In vanilla JS:

var maxScrollTop = el.scrollHeight - el.offsetHeight
cronoklee
  • 5,957
  • 8
  • 47
  • 75
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
  • 13,824
  • 2
  • 79
  • 77