I was trying to get the scroll bar height, after some time i found a idea to get the height:
CSS:
#content {
font-size: 18px;
line-height: 90px;
overflow: hidden;
}
#bt {
background-color: #fff;
width: 10px;
outline: 1px solid red;
position: fixed;
}
HTML:
<button type="button" onclick="barHeight()">Press it</button>
<div id="bt"></div>
<div id="content">
Lorem Ipsum is simply dummy tex.................
</div>
JS:
function barHeight() {
var scrHeight = window.innerHeight; // supposed to be 799 px
var contentBox = document.getElementById("content");
var contentHeight = contentBox.scrollHeight; //
var targetHeight = ( ( scrHeight / contentHeight ) * 100 );
var testBox = document.getElementById("bt");
if(scrHeight < contentHeight) {
testBox.style.height = targetHeight + "%";
} else if( scrHeight > contentHeight ) {
testBox.innerHTML = "0px";
}
}
but when i measured it then its not accurate height as the actual scroll bar looks like.
Thanks in advance!
edited: How can I get the browser's scrollbar sizes? the solution in that link doesn't work for me, at least my script can easily be run and it works for me but not accurately,