I have a vertical menu and I'm trying to find the best way to hide the scrollbar of that area but keep it scrollable. It works well by declaring via CSS the exact size, which in most cases is 17px but this doesn't help on mobiles and other devices.
How can I find the exact size of the scrollbar ( via jquery or pure js ) and use the same amount of px for the padding of .scrollable-box
and the negative margin of .scrollable-inner
?
body {
background: #eee;
font-family: sans-serif;
}
div.sidebar {
padding: 0;
padding-bottom: 60px;
border: 1px solid #ccc;
background: #fff;
position: fixed;
top: 10px;
left: 10px;
bottom: 10px;
width: 280px;
overflow: hidden;
height:300px;
}
div#fixed {
background: #76a7dc;
padding-bottom: 10px;
color: #fff;
padding: 10px;
text-align: center;
}
div.scrollable-box {
height: 100%;
overflow-y: scroll;
width: 100%;
padding-top:20px;
padding-right: 17px;
}
div.scrollable-inner {
margin-right: -17px;
}
<div class="sidebar">
<div id="fixed">
Fixed content here
</div>
<div class="scrollable-box">
<div class="scrollable-inner">
Scrolling content<br><br>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
</div>