Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a custom scrollbar on a div (Facebook style)

I'm wonder how the custom scrollbar on Facebook has been made.

Is it only css or some javascript as well?

If yes can i have an idea of what the code looks like?

This question is specific to Facebook scrollbar style and not how to simply have a custom scrollbar

like image 282
Jerome Ansia Avatar asked Mar 30 '12 15:03

Jerome Ansia


People also ask

How do you add a scroll bar to a div?

To apply, add this style to your div element: overflow-y: scroll; height: XXXpx; The height you specify will be the height of the div and once if you have contents to exceed this height, you have to scroll it.

How do I create a custom scrollbar?

For webkit browsers, you can use the following pseudo elements to customize the browser's scrollbar: ::-webkit-scrollbar the scrollbar. ::-webkit-scrollbar-button the buttons on the scrollbar (arrows pointing upwards and downwards). ::-webkit-scrollbar-thumb the draggable scrolling handle.

How do I add a scrollbar to a section in HTML?

Suppose we want to add a scroll bar option in HTML, use an “overflow” option and set it as auto-enabled for adding both horizontal and vertical scroll bars. If we want to add a vertical bar option in Html, add the line “overflow-y” in the files.


1 Answers

This link should get you started. Long story short, a div that has been styled to look like a scrollbar is used to catch click-and-drag events. Wired up to these events are methods that scroll the contents of another div which is set to an arbitrary height and typically has a css rule of overflow:scroll (there are variants on the css rules but you get the idea).

I'm all about the learning experience -- but after you've learned how it works, I recommend using a library (of which there are many) to do it. It's one of those "don't reinvent" things...

like image 51
Daniel Szabo Avatar answered Sep 22 '22 00:09

Daniel Szabo