How do I get the max value of scrollLeft?

前端 未结 8 558
夕颜
夕颜 2020-12-04 21:28

Okay I\'m using jQuery and currently getting max value of scrollbar doing this:

var $body = $(\'body\');
$body.scrollLeft(99999); // will give me the max val         


        
8条回答
  •  温柔的废话
    2020-12-04 21:48

    You can calculate the maximum value of element.scrollLeft with:

    var maxScrollLeft = element.scrollWidth - element.clientWidth;
    

    Note that there could be some browser specific quirks that I'm not aware of.

提交回复
热议问题