Gathering detailed insights and metrics for scrolled-to-edge
Gathering detailed insights and metrics for scrolled-to-edge
npm install scrolled-to-edge
Typescript
Module System
Node Version
NPM Version
67.2
Supply Chain
98.7
Quality
75.3
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
4,946
Last Day
18
Last Week
37
Last Month
238
Last Year
1,990
14 Commits
1 Forks
1 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.5
Package Id
scrolled-to-edge@1.0.5
Unpacked Size
10.42 kB
Size
3.32 kB
File Count
6
NPM Version
8.3.1
Node Version
16.14.0
Cumulative downloads
Total Downloads
Last day
1,700%
18
Compared to previous day
Last week
-52.6%
37
Compared to previous week
Last month
120.4%
238
Compared to previous month
Last year
30.7%
1,990
Compared to previous year
1
2
A simple react hook and component to detect when the scroll position of the window or a container is at the top, bottom, left or right.
https://chadspencer.dev/scrolledtoedge/
The hook adds an event listener on the window to detect whether the window is scrolled to the start or end of the x and y axis. The hook can be used in any functional component.
import { useScrolledToEdge } from 'scrolled-to-edge';
useScrolledToEdge(callback, offset);
The hook receives in an inline callback function, which is required, and an optional offset value. useScrolledToEdge
will return an event object to the callback that is called when an edge is reached. The returned event object will look something like this:
// At the end of a vertical scroll
{
x: null,
y: "end"
}
// At the start of a vertical scroll and at the end of a horizontal scroll
{
x: "end",
y: "start"
}
A null value indicates the axis is not overflowing or not at the start or end.
Additionally, the hook can be assigned directly to an element via a ref
and the scroll listener will be attached to that element. When using this method the attached component must be able to receive a ref
, so functional components will work only when using forwardRef
. If you are consuming a functional component that you cannot add forwardRef
to, you must use a wrapper element to attach the ref
to and style that container accordingly.
import { useScrolledToEdge } from 'scrolled-to-edge';
const container = useScrolledToEdge(callback, offset);
<div ref={container} />
useBottomScrollListener(
// Required callback that is invoked when an edge is scrolled to.
onChange: () => void,
// Optional offset value in pixels from each edge.
offset?: number
);
Similar to the above ref
example, you can attach the scroll listener to the container by wrapping it in a ScrolledToEdge
component. This component internally uses the same ref method above so the same limitations apply.
import { ScrolledToEdge } from 'scrolled-to-edge';
<ScrolledToEdge callback={() => {}}, offset={number}>
// Container and content here.
</ScrolledToEdge>;
Property | Type | Default | Description |
---|---|---|---|
onChange | function | null | Required callback that is invoked when an edge is scrolled to. |
offset | number | 0 | Optional offset value in pixels from each edge |
import { useScrolledToEdge } from 'scrolled-to-edge';
const App = () => {
useScrolledToEdge(e => console.log(e.x, e.y));
return (
// Content
);
}
import { useScrolledToEdge } from 'scrolled-to-edge';
const App = () => {
scrollingContainer = useScrolledToEdge(e => console.log(e.x, e.y));
return (
<div className="scrolling-container" ref="scrollingContainer">
// Content
</div>
);
}
import { ScrolledToEdge } from 'scrolled-to-edge';
const App = () => {
return (
<ScrolledToEdge onChange={e => console.log(e)}>
<div className="scrolling-container">
// Content
</div>
</ScrolledToEdge>
);
}
The package contains the following directories and files:
1package.json
2CHANGELOG.md
3README.md
4/dist
5 └───/hook
6 └───index.js - 2 KB
7 └───index.js - 1.08 KB
8 └───Scroll.js - 5.12 KB
scrolled-to-edge
does not have any dependencies. However, it does make use of React Hooks so it does have a peer dependency of "react": ">=16.8.0"
.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/14 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
10 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More