Convert Figma logo to code with AI

asvd logodragscroll

micro library for drag-n-drop scrolling style

1,094
168
1,094
37

Top Related Projects

21,948

:ok_hand: Drag and drop so simple it hurts

29,379

Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.

Beautiful and accessible drag and drop for lists with React

A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list✌️

:point_down: Make that shiz draggable

Quick Overview

Dragscroll is a lightweight JavaScript library that enables drag-and-scroll functionality for any scrollable element on a web page. It allows users to click and drag to scroll content, providing an intuitive and smooth scrolling experience across various devices and browsers.

Pros

  • Lightweight and dependency-free
  • Easy to implement with minimal code
  • Works on both desktop and mobile devices
  • Supports both mouse and touch events

Cons

  • Limited customization options
  • May interfere with other drag-based interactions on the page
  • Lacks advanced features like momentum scrolling or snap-to-grid

Code Examples

  1. Basic implementation:
// Add the 'dragscroll' class to any scrollable element
<div class="dragscroll">
  <!-- Scrollable content goes here -->
</div>
  1. Enabling dragscroll programmatically:
// Enable dragscroll on a specific element
dragscroll.reset();
document.getElementById('my-scrollable-element').classList.add('dragscroll');
dragscroll.reset();
  1. Disabling dragscroll:
// Disable dragscroll on a specific element
document.getElementById('my-scrollable-element').classList.remove('dragscroll');
dragscroll.reset();

Getting Started

  1. Include the dragscroll library in your HTML file:
<script src="https://cdn.jsdelivr.net/npm/dragscroll@0.0.8/dragscroll.js"></script>
  1. Add the 'dragscroll' class to any scrollable element:
<div class="dragscroll">
  <!-- Your scrollable content goes here -->
</div>
  1. Initialize dragscroll (if not using the auto-initialization):
dragscroll.reset();

That's it! Your scrollable elements should now have drag-to-scroll functionality.

Competitor Comparisons

21,948

:ok_hand: Drag and drop so simple it hurts

Pros of Dragula

  • More feature-rich, offering drag-and-drop functionality between containers
  • Provides extensive customization options and event hooks
  • Actively maintained with regular updates and a larger community

Cons of Dragula

  • Larger file size and potentially higher performance overhead
  • Steeper learning curve due to more complex API and configuration options
  • May be overkill for simple scrolling needs

Code Comparison

Dragscroll:

<div class="dragscroll">
  <!-- Scrollable content -->
</div>

Dragula:

dragula([
  document.querySelector('#left-container'),
  document.querySelector('#right-container')
]);

Summary

Dragscroll is a lightweight library focused solely on enabling drag-to-scroll functionality, making it ideal for simple scrolling needs. It's easy to implement with minimal code.

Dragula, on the other hand, is a more comprehensive drag-and-drop library that allows for complex interactions between multiple containers. It offers greater flexibility and customization but requires more setup and configuration.

Choose Dragscroll for basic scrolling functionality in a lightweight package. Opt for Dragula when you need advanced drag-and-drop features and are willing to invest time in learning its more extensive API.

29,379

Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.

Pros of Sortable

  • More feature-rich, supporting sorting, dragging, and dropping of elements
  • Offers animation and transition effects for smoother user experience
  • Provides extensive API and event hooks for advanced customization

Cons of Sortable

  • Larger file size and potentially higher performance overhead
  • Steeper learning curve due to more complex API and configuration options

Code Comparison

Dragscroll (basic usage):

<div class="dragscroll">
  <!-- Scrollable content -->
</div>

Sortable (basic usage):

new Sortable(document.querySelector('#list'), {
  animation: 150,
  ghostClass: 'blue-background-class'
});

Key Differences

  • Dragscroll focuses solely on scrolling content, while Sortable offers comprehensive drag-and-drop functionality
  • Sortable provides more advanced features like multi-list sorting and nested lists
  • Dragscroll is more lightweight and easier to implement for simple scrolling needs

Use Cases

  • Dragscroll: Ideal for implementing custom scrollbars or panning large images
  • Sortable: Better suited for creating interactive lists, kanban boards, or drag-and-drop interfaces

Both libraries serve different purposes, with Dragscroll being a simpler solution for scrolling and Sortable offering more robust drag-and-drop capabilities. Choose based on your specific project requirements and complexity needs.

Beautiful and accessible drag and drop for lists with React

Pros of react-beautiful-dnd

  • Specifically designed for React applications, offering seamless integration
  • Provides a rich set of features including drag handles, multi-drag, and auto-scrolling
  • Offers excellent accessibility support and keyboard navigation

Cons of react-beautiful-dnd

  • More complex setup and configuration compared to dragscroll's simplicity
  • Limited to React applications, while dragscroll is framework-agnostic
  • Larger bundle size due to its comprehensive feature set

Code Comparison

dragscroll:

<div class="dragscroll">
  <!-- Scrollable content -->
</div>

react-beautiful-dnd:

<DragDropContext onDragEnd={onDragEnd}>
  <Droppable droppableId="list">
    {(provided) => (
      <div {...provided.droppableProps} ref={provided.innerRef}>
        {/* Draggable items */}
      </div>
    )}
  </Droppable>
</DragDropContext>

The code comparison highlights the simplicity of dragscroll, which requires minimal setup, versus the more structured approach of react-beautiful-dnd. While dragscroll focuses on enabling drag-to-scroll functionality with a single class, react-beautiful-dnd provides a comprehensive drag-and-drop system with more granular control over the dragging experience.

A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list✌️

Pros of react-sortable-hoc

  • Specifically designed for React applications, providing seamless integration
  • Offers advanced features like drag handles, auto-scrolling, and multi-list sorting
  • Provides a higher-level abstraction for complex sorting scenarios

Cons of react-sortable-hoc

  • Larger bundle size due to more features and React-specific implementation
  • Steeper learning curve for developers unfamiliar with higher-order components
  • May be overkill for simple drag-and-scroll functionality

Code Comparison

react-sortable-hoc:

import { SortableContainer, SortableElement } from 'react-sortable-hoc';

const SortableItem = SortableElement(({value}) => <li>{value}</li>);
const SortableList = SortableContainer(({items}) => {
  return (
    <ul>
      {items.map((value, index) => (
        <SortableItem key={`item-${index}`} index={index} value={value} />
      ))}
    </ul>
  );
});

dragscroll:

<div class="dragscroll">
  <!-- Scrollable content -->
</div>

<script src="dragscroll.js"></script>

Summary

While dragscroll provides a simple solution for drag-to-scroll functionality, react-sortable-hoc offers a more comprehensive toolkit for creating sortable lists in React applications. The choice between the two depends on the specific requirements of the project and the complexity of the desired sorting functionality.

:point_down: Make that shiz draggable

Pros of Draggabilly

  • More feature-rich, offering options like containment, grid snapping, and multiple handles
  • Better touch device support with multi-touch handling
  • Provides events and methods for more granular control over dragging behavior

Cons of Draggabilly

  • Larger file size and more complex codebase
  • Requires more setup and configuration for basic use cases
  • May have a steeper learning curve for beginners

Code Comparison

Dragscroll (basic usage):

<div class="dragscroll">
  <!-- Scrollable content -->
</div>

Draggabilly (basic usage):

var elem = document.querySelector('#draggable');
var draggie = new Draggabilly(elem, {
  // options
});

Both libraries provide drag functionality, but Draggabilly offers more customization and control at the cost of simplicity. Dragscroll is lightweight and easy to implement for basic scrolling needs, while Draggabilly is better suited for complex dragging interactions and precise positioning of elements.

Dragscroll is ideal for simple scrollable content, whereas Draggabilly excels in creating draggable UI elements with advanced features. The choice between the two depends on the specific requirements of your project and the level of control you need over the dragging behavior.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

dragscroll

Dragscroll is a micro JavaScript library (910 bytes minified) which enables scrolling via holding the mouse button ("drag and drop" or "click and hold" style, online demo). It has no dependencies and is written in vanilla JavaScript (which means it works anywhere).

Usage

Download the and unpack distribution, or install it using Bower:

$ bower install dragscroll

or npm:

$ npm install dragscroll

Load the dragscroll.js in a preferable way (that is an UMD module):

<script src="path/to/dragscroll.js"></script>

Add the dragscroll class to a scrollable element:

<div class=dragscroll>
    Big text goes here...
</div>

That's it! Now you can scroll it by dragging. You can also add the dragscroll class to the <body> element and drag the whole page.

Keep in mind that now it is not possible to select the content with mouse, so apply the cursor: default; CSS style to prevent confusing the users (or even cursor: grab; in case the content is not a text).

If you add or remove the dragscroll class dynamically, invoke dragscroll.reset() to update the listeners.

You can also add the nochilddrag attribute to a scrollable element, which will only enable drag-scrolling for an element itself, but not for its subchildren. This can be usefull, if you want to enable the scrolling the area by dragging its empty space, but keep the opportunity to select the text (see example).

Follow me on twitter: https://twitter.com/asvd0

NPM DownloadsLast 30 Days