Finding the maximum bottom value of scrollTop on a div?

前端 未结 4 1070
旧巷少年郎
旧巷少年郎 2020-12-29 05:23

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

相关标签:
4条回答
  • 2020-12-29 05:33

    In vanilla JS:

    var maxScrollTop = el.scrollHeight - el.offsetHeight
    
    0 讨论(0)
  • 2020-12-29 05:51

    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+
    
    0 讨论(0)
  • 2020-12-29 05:55

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

    $('#box').prop('scrollHeight') - $('#box').innerHeight();
    
    0 讨论(0)
  • 2020-12-29 05:56

    here you go:

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

    Simplified

    0 讨论(0)
提交回复
热议问题