I'm not sure if "sticky" is the term for this, but is there a way to make the scrollbar from overflow:auto
stay visible?
I have a rather large table that I want to be scrollable horizontally; however, the table is fairly tall as well, so when the page loads the horizontal scrollbar is not within the viewport of the browser, so it's rather hard to tell that the table is scrollable at all.
<div style = 'width:900px;overflow:auto'>
<table>
<!-- Very large table here -->
</table>
</div>
The scroll bar appears below the table, but unfortunately the table is so tall you can't see it unless you scroll down.
I'd like to have the horizontal scrollbar stay visible even if the table goes off the screen, maybe fixed to the bottom of the viewport. Ideally I'd like to do it using only CSS or a minimal amount of javascript.
@Mahn - I made a small update to the following function:
The if statement looks if the container offsetWidth is smaller than the scrollWidth. Else you will also get a fixed scrollbar if the content happens to be smaller than the container. I did not like having a disfunctional scrollbar, hence this edit.
Here's my take, @user2451227's is almost perfect, but didn't work with nested overflowed elements and had a number of performance issues, so I rewrote it:
Usage: Add the class
fixed-scrollbar-container
to your horizontally overflowed element, then include this code. If the container is updated or changes in size, run$(window).trigger("resize.fixedbar");
to update the bar.Demo: http://jsfiddle.net/8zoks7wz/1/
How about restricting the height of the containing div so it stays within the body? You could then have the table scroll within that div.
Working jsfiddle here: http://jsfiddle.net/fybLK/
Here, I've set the html and body to 100% height so that the containing div can be sized.
Here is a script for that http://jsfiddle.net/TBnqw/2288/
It is a quick test rather than a complete generic plugin, but is a good start, I think