How can I determine the height of a horizontal scrollbar, or the width of a vertical one, in JavaScript?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Tested in Chrome, FF, IE8, IE11.
You can determine
window
scroll bar withdocument
as below using jquery + javascript:if you are looking for a simple operation, just mix plain dom js and jquery,
returns the size of current page scrollbar. (if it is visible or else will return 0)
The way
Antiscroll.js
does it in it's code is:The code is from here: https://github.com/LearnBoost/antiscroll/blob/master/antiscroll.js#L447
If you already have an element with scrollbars on it use:
If there is no horzintscrollbar present the function will retun 0