OverlayScrollbars for Vue

0.5.9 · active · verified Sun Apr 19

OverlayScrollbars-Vue is the official Vue wrapper for the OverlayScrollbars library, providing highly customizable scrollbars that replace native browser scrollbars for consistent cross-browser styling and behavior. It integrates seamlessly into Vue 3 applications, offering both a component-based API (`OverlayScrollbarsComponent`) and a composable API for more granular control. Currently at version `0.5.9`, the package maintains an active release cadence, often aligning with updates to the underlying `OverlayScrollbars` core library, which is at `v2.15.0`. Recent core library updates have introduced features like configurable click-scroll behavior and performance optimizations such as a `sleep` function and enhanced debounce options. Its key differentiators include extensive customization options, performance optimizations like deferred initialization, and robust event handling, making it a powerful choice for enhancing UI/UX in Vue projects demanding bespoke scrollbar aesthetics and functionality.

Common errors

Warnings

Install

Imports

Quickstart

Initializes a custom scrollbar for a content area in a Vue component, demonstrating basic component usage with options, event handling, and deferred initialization for performance.

import { defineComponent } from 'vue';
import { OverlayScrollbarsComponent } from 'overlayscrollbars-vue';
import 'overlayscrollbars/overlayscrollbars.css';

export default defineComponent({
  components: { OverlayScrollbarsComponent },
  data() {
    return {
      content: Array.from({ length: 50 }, (_, i) => `Item ${i + 1}`).join('<br>')
    };
  },
  methods: {
    onScroll(instance, event) {
      console.log('Scroll event!', event, instance.state().scrollOffset);
    },
    onInitialized(instance) {
      console.log('OverlayScrollbars initialized:', instance);
    }
  },
  template: `
    <div style="width: 300px; height: 200px; border: 1px solid #ccc;">
      <h3>Scrollable Content</h3>
      <OverlayScrollbarsComponent
        element="div"
        :options="{ scrollbars: { autoHide: 'scroll', autoHideDelay: 200 } }"
        :events="{ scroll: onScroll, initialized: onInitialized }"
        defer
        style="height: 100%;"
      >
        <div v-html="content"></div>
      </OverlayScrollbarsComponent>
    </div>
  `
});

view raw JSON →