Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
146
rated 0 times [  150] [ 4]  / answers: 1 / hits: 31384  / 10 Years ago, thu, july 17, 2014, 12:00:00

How can I get the browser scrollbar height? Does JS have a built-in function for this case?
Somebody please help me out of this.


More From » scrollbar

 Answers
14

There isn't a built-in method for this. However, the scrollbar's height is supposed to give an indication of how much of the available content fits within the available viewport. Going by that, we can determine it like:



var sbHeight = window.innerHeight * (window.innerHeight / document.body.offsetHeight);


Where window.innerHeight / document.body.offsetHeight is the percentage of content visible currently. We multiple that with the available viewport height to get the approximate scrollbar height.



Note: Different browsers may add/reduce some pixels to/from the scrolbar height.


[#70175] Tuesday, July 15, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
peytont

Total Points: 215
Total Questions: 110
Total Answers: 111

Location: Armenia
Member since Sat, Dec 31, 2022
1 Year ago
;