Vue Dragscroll Directive

4.0.6 · active · verified Sun Apr 19

vue-dragscroll is a lightweight Vue.js directive designed to enable scrolling of an HTML element via a drag-and-drop or click-and-hold mouse interaction. The current stable version, 4.0.6, is specifically built for Vue 3 projects and leverages modern tooling such as TypeScript and Vite. This package offers a simple, declarative way to implement interactive scrolling without needing complex configurations, distinguishing itself as a focused directive rather than a comprehensive scrolling utility. It provides an intuitive user experience for horizontally or vertically scrollable containers. Release cadence has historically been tied to major Vue version compatibility, with key updates like adding Vue 3 support and migrating to a TypeScript codebase.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to globally register the `dragscroll` directive and apply it to a scrollable `div` in a Vue 3 application. It creates a simple horizontal scroll container populated with items that can be scrolled by dragging with the mouse.

import { createApp } from 'vue';
import { dragscroll } from 'vue-dragscroll';

const app = createApp({
  template: `
    <div v-dragscroll class="scrollable-container">
      <div v-for="n in 10" :key="n" class="scroll-item">
        Item {{ n }}
      </div>
    </div>
  `,
  setup() {
    // Component logic here if needed
  }
});

app.directive('dragscroll', dragscroll);
app.mount('#app');

// Basic styling for demonstration purposes
const style = document.createElement('style');
style.innerHTML = `
.scrollable-container {
  width: 400px;
  height: 150px;
  overflow-x: scroll;
  overflow-y: hidden; /* Prevent vertical scrolling */
  white-space: nowrap;
  border: 1px solid #ccc;
  cursor: grab;
  user-select: none;
  padding: 10px;
}
.scrollable-container:active {
  cursor: grabbing;
}
.scroll-item {
  display: inline-block;
  width: 120px;
  height: 100%;
  background-color: #f0f0f0;
  margin-right: 10px;
  line-height: 130px;
  text-align: center;
  border: 1px dashed #aaa;
  vertical-align: middle;
}
`;
document.head.appendChild(style);

view raw JSON →