OverlayScrollbars Documentation

repository·master·Indexed 26 days ago

https://github.com/kingsora/overlayscrollbars

A library providing highly customizable, cross-browser scrollbars that replace native browser scrollbars with a consistent, stylable implementation. Includes the core vanilla JavaScript library and official wrappers for Angular (overlayscrollbars-ngx), React (overlayscrollbars-react), SolidJS (overlayscrollbars-solid), Svelte (overlayscrollbars-svelte), and Vue (overlayscrollbars-vue).

Tokens
12.2K
Snippets
35
Records
75
Agent score
89%

What's inside OverlayScrollbars

  1. Prevent initialization flickering

    master

    To prevent the brief moment where native scrollbars are visible before OverlayScrollbars initializes, add the data-overlayscrollbars-initialize attribute to your target element. If initializing the body, add the attribute to both the html and body elements.

    <!-- for the body element -->
    <html data-overlayscrollbars-initialize>
      <head></head>
      <body data-overlayscrollbars-initialize></body>
    </html>
    
    <!-- for all other elements -->
    <div data-overlayscrollbars-initialize>
      OverlayScrollbars is applied to this div
    </div>
  2. Manual Download & Embedding

    master

    You can use OverlayScrollbars without a bundler by downloading files from a Release or using a CDN.

    • Use .browser files for general use.
    • Use .es5 for older browser support, otherwise use .es6.
    • Use .min files for production.

    Access the API via the global OverlayScrollbarsGlobal object.

    <link type="text/css" href="path/to/overlayscrollbars.css" rel="stylesheet" />
    <script type="text/javascript" src="path/to/overlayscrollbars.browser.es.js" defer></script>
    var { 
      OverlayScrollbars, 
      ScrollbarsHidingPlugin, 
      SizeObserverPlugin, 
      ClickScrollPlugin  
    } = OverlayScrollbarsGlobal;
  3. Install OverlayScrollbars for Angular

    master

    To use OverlayScrollbars in an Angular project, you must install the wrapper package and its required peer dependencies.

    1. Install the Angular wrapper: npm install overlayscrollbars-ngx

    2. Install the core vanilla JavaScript library: npm install overlayscrollbars

    3. Ensure @angular/core and @angular/common are available in your project.

    npm install overlayscrollbars-ngx
    npm install overlayscrollbars
  4. Limit or adjust the scrollbar handle length

    master

    You can control the size of the scrollbar handle by applying CSS min-width, max-width, min-height, or max-height to the handle classes.

    Note: Do not use the width or height properties, as these are managed automatically by the plugin. To force a constant handle size, set both the minimum and maximum properties to the same value.

    • Horizontal handles use: .os-scrollbar-horizontal .os-scrollbar-handle
    • Vertical handles use: .os-scrollbar-vertical .os-scrollbar-handle
    /* horizontal boundaries */
    .os-scrollbar-horizontal .os-scrollbar-handle {
      min-width: 50px;
      max-width: 200px;
    }
    /* vertical boundaries */
    .os-scrollbar-vertical .os-scrollbar-handle {
      min-height: 40px;
      max-height: 40px;
    }
  5. Style OverlayScrollbars using built-in themes

    master

    OverlayScrollbars includes two default themes: os-theme-dark and os-theme-light. You can apply these by setting the scrollbars.theme option during initialization.

    OverlayScrollbars(document.body, {
      scrollbars: {
        theme: 'os-theme-dark'
      }
    });
  6. Install OverlayScrollbars for React

    master

    To use OverlayScrollbars in a React project, you must install both the React wrapper and the core vanilla JavaScript library. Ensure you also have react installed in your project.

    1. Install the React wrapper:
      npm install overlayscrollbars-react
    2. Install the core library (peer dependency):
      npm install overlayscrollbars
    npm install overlayscrollbars-react
    npm install overlayscrollbars
  7. Install OverlayScrollbars via npm

    master

    Install the overlayscrollbars package using your preferred package manager. Once installed, you can import the core library, plugins, and the required CSS file.

    ```sh
    npm install overlayscrollbars
    import 'overlayscrollbars/overlayscrollbars.css';
    import { 
      OverlayScrollbars, 
      ScrollbarsHidingPlugin, 
      SizeObserverPlugin, 
      ClickScrollPlugin 
    } from 'overlayscrollbars';

    Note: If 'overlayscrollbars/overlayscrollbars.css' is not found, try using 'overlayscrollbars/styles/overlayscrollbars.css' instead.

  8. Install and consume OverlayScrollbars plugins

    master

    OverlayScrollbars uses a plugin system to keep the core lightweight. Features like scrollbar hiding for older browsers or click-to-scroll are provided via plugins. Plugins must be added using OverlayScrollbars.plugin() before creating instances that require them.

    import { 
      OverlayScrollbars, 
      ScrollbarsHidingPlugin, 
      SizeObserverPlugin, 
      ClickScrollPlugin 
    } from 'overlayscrollbars';
    
    // Single plugin
    OverlayScrollbars.plugin(ScrollbarsHidingPlugin);
    
    // Multiple plugins
    OverlayScrollbars.plugin([SizeObserverPlugin, ClickScrollPlugin]);