KingSora / OverlayScrollbars

A javascript scrollbar plugin that hides the native scrollbars, provides custom styleable overlay scrollbars, and preserves the native functionality and feel.
https://kingsora.github.io/OverlayScrollbars
MIT License
3.71k stars 215 forks source link

How do I make the scrollbar sticky? #619

Closed axelthat closed 3 months ago

axelthat commented 4 months ago

My table is scrollable horizontally if content is too big. The problem with this is I have to scroll all the way to the bottom to use the scrollbar. Ofc, I could use Shift + ScrollWheel to horizontally scroll but most of my user base don't even know that this key combination even exist.

Is it possible to make the scrollbar sticky? I tried the following css on the scrollbar but it don't seem to work:

position: sticky;
top: 0;

Here's a reproducible example: https://stackblitz.com/edit/vitejs-vite-k4wqf4?file=src%2Fmain.ts

Thank you!

KingSora commented 4 months ago

Good day @axelthat :)

If your whole document consists of only the table you can make the scrollbar fixed: https://stackblitz.com/edit/vitejs-vite-cttbhv?file=src%2Fstyle.css,src%2Fmain.ts

If your table is embedded somewhere else on your page you have to come up with your own markup to make this possible.. Its certainly possible and has been done. One example would be on the v1 docs page: https://kingsora.github.io/OverlayScrollbars/v1/#!faq where you can find a table if you scroll down. The source code of the v1 docs can be found here: https://github.com/KingSora/OverlayScrollbars/tree/master/docs/v1

axelthat commented 4 months ago

@KingSora Good day to you too.

Unfortunately that doesn't help my case because my table don't have a fixed height. And frankly, I don't want to – as my page would have too many scrollbar clutter. I want the table to just use the default body scrollbar.

Do you think it's possible to somehow make the virtual scroll bar sticky using position: sticky?

Thank you!

KingSora commented 3 months ago

@axelthat Maybe this example is more what you would expect: https://stackblitz.com/edit/vitejs-vite-mgh3cg?file=src%2Fstyle.css,src%2Fmain.ts

I've moved the scrollbars to the parent element of the #table element because the parent is responsible for the vertical scrolling. This markup makes the position: sticky style possible.

KingSora commented 3 months ago

@axelthat does the last example solve your issue?

axelthat commented 3 months ago

Hi @KingSora. That works perfectly for my use case. Thank you for your efforts.