Installations
npm install scrolled-to-edge
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
16.14.0
NPM Version
8.3.1
Score
67.2
Supply Chain
98.7
Quality
75.3
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
chadspencer
Download Statistics
Total Downloads
4,946
Last Day
18
Last Week
37
Last Month
238
Last Year
1,990
GitHub Statistics
14 Commits
1 Forks
1 Watching
1 Branches
1 Contributors
Bundle Size
3.08 kB
Minified
1.29 kB
Minified + Gzipped
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
4,946
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
2
scrolled-to-edge
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.
Homepage
https://chadspencer.dev/scrolledtoedge/
Usage
Hook
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} />
Parameters
useBottomScrollListener(
// Required callback that is invoked when an edge is scrolled to.
onChange: () => void,
// Optional offset value in pixels from each edge.
offset?: number
);
Component
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>;
Props
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 |
Examples
Hook on Window
import { useScrolledToEdge } from 'scrolled-to-edge';
const App = () => {
useScrolledToEdge(e => console.log(e.x, e.y));
return (
// Content
);
}
Hook on Container
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>
);
}
Component
import { ScrolledToEdge } from 'scrolled-to-edge';
const App = () => {
return (
<ScrolledToEdge onChange={e => console.log(e)}>
<div className="scrolling-container">
// Content
</div>
</ScrolledToEdge>
);
}
Package Contents
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
Dependencies
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
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
10 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
Score
1.3
/10
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