Custom Vue Scrollbar

0.0.8 · active · verified Sun Apr 19

custom-vue-scrollbar is a lightweight (4.5KB gzipped) and high-performance Vue 3 component designed to provide customizable scrollbars while maintaining a native-like scrolling experience. As of version 0.0.8, it is in early development, with an irregular release cadence. It aims to offer advanced features like floating scrollbars (which fix at the bottom of the screen if the container exceeds visible area), toggleable native/simulated scroll modes for diverse use cases (e.g., synchronizing with outer elements), and automatic scrollbar hiding with configurable delay options. A key differentiator is its emphasis on minimal intrusion, few APIs, and direct access to the native scroll element, distinguishing it from libraries that significantly alter native scrolling behavior or introduce complex abstractions like `better-scroll`. It supports TypeScript and prioritizes performance, outperforming older alternatives by optimizing rendering and minimizing JavaScript-level calculations.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to register and use the CustomScrollbar component, applying necessary styles and accessing the native scroll element via a ref for programmatic scrolling.

import { createApp, ref } from 'vue';
import CustomScrollbar from 'custom-vue-scrollbar';
import 'custom-vue-scrollbar/dist/style.css';

const app = createApp({
  template: `
    <custom-scrollbar ref="scrollRef" :style="{ width: '500px', height: '300px', border: '1px solid #ccc', margin: '20px' }">
        <div :style="{ width: '1000px', height: '600px', background: 'linear-gradient(to bottom right, #f0f8ff, #add8e6)' }">
            <p>Some great content that extends beyond the scroll area, allowing the custom scrollbar to demonstrate its functionality.</p>
            <p>Click the button below to scroll to the top smoothly.</p>
            <button @click="handleClickScrollToTop">Scroll to Top</button>
        </div>
    </custom-scrollbar>
  `,
  setup() {
    const scrollRef = ref<{ scrollEl: HTMLDivElement }>();

    const handleClickScrollToTop = () => {
      if (scrollRef.value?.scrollEl) {
        scrollRef.value.scrollEl.scrollTo({ top: 0, behavior: 'smooth' });
      }
    };
    return { scrollRef, handleClickScrollToTop };
  }
});
app.component(CustomScrollbar.name, CustomScrollbar);
app.mount('#app');

view raw JSON →