gemini-scrollbar custom overlay-scrollbars with native scrolling mechanism for web applications (when needed)

npm i gemini-scrollbar --save
bower install gemini-scrollbar --save

Problem Description

Nowadays, many OS's provides “overlay-scrollbars”. Those scrollbars looks nice and works well (mostly mobile browsers). I am OK with that, but building web apps, you may still found yourself searching on how to customize the remaining portion of ‘ugly’ scrollbars out there, specially when they do not fit with your designs. e.g: “having a sidebar with a dark-background + native-non-floating-scrollbars on them” ...hum, ugly. Yes, the problem can be merely visual, but for me is a way of enhancing the user experience.

Constraints

  • Fallback to the native scrollbars when the OS/browser supports “overlay-scrollbars” natively
  • Mimic the native scrollbar behaviour when replaced with the custom ones (click, drag...)
  • IE9+ support

Solution Proposal

First, we check the scrollbar size, if the scrollbar size is equal to zero (which means the scrollbars are already “over the content” natively) then we do nothing, otherwise we “hide” the native scrollbar (leaving its functionality intact) and create a new pair of “scrollbars” made of divs that you can fully customize with CSS. Those “scrollbars” will update its position while scrolling for visual feedback and will also respond if you click or drag them.

Functional Examples (for demo purposes, not intended to be perfect shot replicas)

Title
  • Clean the house
  • Take out the thrash
  • Do the dishes
  • Feed the dog
  • Mow the law
  • Clean the pool
  • Have a beer
  • Clean the house
  • Take out the thrash
  • Do the dishes
  • Feed the dog
  • Mow the law
  • Clean the pool
  • Have a beer
  • Clean the house
  • Take out the thrash
  • Do the dishes
  • Feed the dog
  • Mow the law
  • Clean the pool
  • Have a beer
source image and inspiration from Matt Gentile
<!DOCTYPE html>
<html lang="en">

<-- BEGIN head -->
<head>
   <meta charset="utf-8" />
   <title>GeminiScrollbar – Fully skinnable scrollbars with native scrolling.</title>
</head>

<-- BEGIN body -->
<body>
source image and inspiration from Orman Clark

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Posted 9 hours ago by noeldelgado

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quis facere debitis ullam, quae quidem, impedit culpa nam repellat in voluptatibus esse ab harum, hic? Aliquam nesciunt voluptates repellendus assumenda labore.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Porro quos voluptate doloribus. Optio unde inventore, tempore nemo repellat expedita! Quod, accusamus nobis iure. Aliquam quibusdam, nemo explicabo ipsum provident asperiores.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quaerat, qui, rem! Debitis cum maiores iste, possimus! Obcaecati accusamus eaque expedita quo soluta quis, repudiandae similique, veritatis repellendus facere suscipit! Et!

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Harum doloremque repellat praesentium quae et consectetur iure quos porro, provident voluptates reprehenderit a. Accusamus ut, quaerat asperiores blanditiis voluptate, sint facilis.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus beatae inventore nobis esse temporibus exercitationem eos illo minima non magnam, provident sit doloribus maiores odio in animi quidem unde. Perferendis.

source image and inspiration from Orman Clark

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sapiente sint quos at. Quae in voluptate, autem ipsa porro quisquam architecto eos impedit laudantium, dolorem blanditiis fugiat maxime, veritatis voluptas temporibus?

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Hic consequuntur, incidunt explicabo reiciendis, reprehenderit voluptates dolorum possimus quo consequatur ratione quasi ipsa provident, ducimus similique. Ipsum quo alias exercitationem corrupti?

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Necessitatibus modi, inventore quaerat, distinctio unde est. Omnis quibusdam aspernatur ad inventore nisi velit, eius ab, cupiditate eum unde, architecto non quam?

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate laborum quas laboriosam officiis eum accusamus, aspernatur maiores. Odio aperiam beatae recusandae assumenda in, ipsa, aliquam numquam qui quis perferendis, ex.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis quae dignissimos laudantium delectus, distinctio eum quia eaque voluptatibus. Odio quo expedita placeat quae, nobis alias iusto at cum, ut excepturi!

source image and inspiration from Al Shaw

Lorem ipsum dolor sit amet

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Amet mollitia vero quam, nisi possimus dolorem asperiores, molestiae sit voluptatibus alias consequuntur laudantium repellat ea quidem quaerat rerum perspiciatis iste adipisci.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda earum facilis sed nihil numquam at accusamus eum error eaque alias hic sint rem consequatur impedit tempore, dolor, quos, quae esse?

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore maiores maxime corrupti quisquam. Dignissimos sunt error voluptatibus repellat consequatur illo, aliquid nihil maxime veniam repudiandae, provident et sit, reiciendis dicta.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae id amet deserunt voluptate maiores sunt aut eligendi totam nesciunt magnam illo consectetur aspernatur at voluptatem, qui unde ullam omnis voluptates.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Id assumenda et fugiat placeat enim quas, voluptas odio aperiam in quibusdam beatae eaque minima. Consequuntur pariatur, doloremque, odit dolorem ullam sunt!

source image and inspiration from Matt Gentile

Lorem ipsum dolor sit amet

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Amet mollitia vero quam, nisi possimus dolorem asperiores, molestiae sit voluptatibus alias consequuntur laudantium repellat ea quidem quaerat rerum perspiciatis iste adipisci.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Assumenda earum facilis sed nihil numquam at accusamus eum error eaque alias hic sint rem consequatur impedit tempore, dolor, quos, quae esse?

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore maiores maxime corrupti quisquam. Dignissimos sunt error voluptatibus repellat consequatur illo, aliquid nihil maxime veniam repudiandae, provident et sit, reiciendis dicta.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae id amet deserunt voluptate maiores sunt aut eligendi totam nesciunt magnam illo consectetur aspernatur at voluptatem, qui unde ullam omnis voluptates.

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Id assumenda et fugiat placeat enim quas, voluptas odio aperiam in quibusdam beatae eaque minima. Consequuntur pariatur, doloremque, odit dolorem ullam sunt!

source image and inspiration from Tanveer Junayed 

License

Copyright © Noel Delgado.

Licensed under the MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.