Custom overlay-scrollbars with native scrolling mechanism for web applications (if needed).
There is a React wrapper too — react-gemini-scrollbar.
Nowadays, some OS’s provides “overlay-scrollbars” natively. Those scrollbars look nice and work well (mostly mobile browsers and OSX opt-in). The problem came when you have to customize the remaining ‘ugly’ scrollbars out there. e.g: “having a sidebar with a dark background + native-non-floating-scrollbars” ...hum, ugly. Even when this problem can be merely visual, for me is a way of enhancing the user experience.
- Fallbacks to use the native scrollbars when the OS/browser supports “overlay-scrollbars”.
- Mimics the scrollbar behaviour when replaced with the custom ones (click, drag...).
- IE9+ support.
Check the scrollbar size. If the scrollbar size is zero (which means the scrollbars are already “over the content”) then we do nothing. Otherwise we simply “hide” native scrollbar and show custom in its place.
npm i gemini-scrollbar --save
bower install gemini-scrollbar --save
var GeminiScrollbar =var myScrollbar =element: document;
Or, you can add the relevant files in your document.
||The element to apply scrollbars|
||Show scrollbars upon hovering|
||Create and append the require HTMLElements at runtime.|
||Force Gemini scrollbars even if native overlay-scrollbars are available. Useful for development.|
||Hook by which clients can be notified of resize events.|
||Sets the minimum size of the thumbs.|
|create||Bind the events, create the required elements and display the scrollbars.|
|update||Recalculate the viewbox and scrollbar dimensions.|
|destroy||Unbind the events and remove the custom scrollbar elements.|
|getViewElement||Returns the scrollable element|
You can change the styles of the scrollbars using CSS. e.g:
/* override gemini-scrollbar default styles *//* vertical scrollbar track *//* horizontal scrollbar track *//* scrollbar thumb */
native overlay-scrollbar: We check the scrollbar size using this approach by David Walsh. If the scrollbar size is zero (which means the scrollbars are “over the content”) then we do nothing but add the
gm-preventedclass selector to the element, which contains the non-standard
-webkit-overflow-scrolling: touch;declaration for web devices to use momentum-based scrolling. No event binding, element creation... nothing, in this case, we leave the OS/browser do its job. Why? you already have nice looking scrollbars for free.
::-webkit-scrollbar: If you plan to use gemini-scrollbar on your application I highly recommend you removing any Webkit scrollbar styles you may have, why? using the
-webkit-prefixed pseudo-elements will cause Webkit turning off its built-in scrollbar rendering, interfering with our scrollbar-size-check. You can read a bit more about this issue on this commit.
create method: The custom scrollbars will not render until you call the
createmethod on the instance. i.e:
required height: To avoid unexpected results, it is recommended that you specify the
heightproperty with a value to the element you applying the custom scrollbars (or to its parent).
body tag: If you want to apply custom scrollbars to
body, make sure to declare a
heightvalue either to the
:rootpseudo-class or to the
createElements option: The
createElementsoption specify wheater or not gemini-scrollbar should create and append the require HTMLElements at runtime. Its default value is
true. Passing this option as
falsewill assume that you to have added the required markup with the specific CSS class selectors on them for it to work. i.e:<!-- (createElements: false) example markup -->All your content goes here.
This way you can be sure the library will not touch/change your nodes structure. You can read more about the reason of this option on this commit.
- react-gemini-scrollbar - React wrapper
MIT © Noel Delgado