
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
react-scroll-ondrag
Advanced tools
Scroll your elements by dragging your mouse
You can see the simplest demo here: Live demo
$ npm install --save react-scroll-ondrag
Run examples:
$ npm ci
$ cd examples
$ npm ci
$ npm start
import { useRef } from 'react';
import useScrollOnDrag from 'react-scroll-ondrag';
const App = () => {
const ref = useRef();
const { events } = useScrollOnDrag(ref);
return <div {...events} ref={ref} />;
};
Type: a React ref
, required
A ref
to the DOM element whose scroll position you want to control
Type: object
Type: function: ({ dx: Integer, dy: Integer }) => void
Default:
// ref is the first argument to the hook, documented above
({ dx, dy }) => {
const maxHorizontalScroll = dom => dom.scrollWidth - dom.clientWidth;
const maxVerticalScroll = dom => dom.scrollHeight - dom.clientHeight;
const offsetX = Math.min(maxHorizontalScroll(ref.current), ref.current.scrollLeft + dx);
ref.current.scrollLeft = offsetX; // eslint-disable-line no-param-reassign
const offsetY = Math.min(maxVerticalScroll(ref.current), ref.current.scrollTop + dy);
ref.current.scrollTop = offsetY; // eslint-disable-line no-param-reassign
}
Used to customize scroll, i.e., scroll only in horizontal direction, change scroll speed, etc
Type: function: () => void
Called when scrolling by dragging starts
Type: function: () => void
Called when scrolling by dragging ends
Type: object
, shape: { events: { onMouseDown } }
An object with the events to inject to the controlled element.
See the LICENSE file for license rights and limitations (MIT).
FAQs
React library for scrolling elements by dragging the mouse
The npm package react-scroll-ondrag receives a total of 667 weekly downloads. As such, react-scroll-ondrag popularity was classified as not popular.
We found that react-scroll-ondrag demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.