Gathering detailed insights and metrics for react-smooth-scroll-hook
Gathering detailed insights and metrics for react-smooth-scroll-hook
Gathering detailed insights and metrics for react-smooth-scroll-hook
Gathering detailed insights and metrics for react-smooth-scroll-hook
scroll-into-view-if-needed
Ponyfill for upcoming Element.scrollIntoView() APIs like scrollMode: if-needed, behavior: smooth and block: center
react-infinite-scroll-hook
A simple hook to create infinite scroll components
smooth-scroll-into-view-if-needed
Ponyfill for smooth scrolling elements into view (if needed!)
react-scroll-to-bottom
React container that will auto scroll to bottom
npm install react-smooth-scroll-hook
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
117 Stars
84 Commits
5 Forks
3 Watching
3 Branches
2 Contributors
Updated on 21 Oct 2024
Minified
Minified + Gzipped
TypeScript (93.08%)
JavaScript (5.58%)
HTML (1.23%)
CSS (0.1%)
Cumulative downloads
Total Downloads
Last day
3.9%
322
Compared to previous day
Last week
-6.1%
1,506
Compared to previous week
Last month
5.8%
6,646
Compared to previous month
Last year
-53.1%
81,140
Compared to previous year
34
Powered By GE-COMPONENTS From YY GFE TEAM
English | 简体ä¸æ–‡
It provided useSmoothScroll
hook for finishing smooth scroll behaviour in react component, and useScrollWatch
to return some information in scroll container.
It 's a more convenient way to replace native scrollTo
api.
Storybook Docs are Here.
🚀 You don't need to warn about compatibility, it use requsetAnimationFrame
api to finish smooth scroll behaviour.
👉 Provide direction
option ,you can set x
for horizontal, y
for vertical.
💧 No Third Party dependencies, light and pure.
1npm install react-smooth-scroll-hook
1import React, { useRef } from 'react'; 2import useSmoothScroll from 'react-smooth-scroll-hook'; 3export const Demo = () => { 4 // A custom scroll container 5 const ref = useRef(null); 6 7 // Also support document.body / document.documentElement, and you don't need to set a ref passing to jsx 8 const ref = useRef(document.body); 9 10 const { scrollTo } = useSmoothScroll({ 11 ref, 12 speed: 100, 13 direction: 'y', 14 }); 15 16 return ( 17 <> 18 <button onClick={() => scrollTo('#item-20')}>scrollTo('#item-20')</button> 19 <div 20 // if use custom scroll container, pass ref 21 ref={ref} 22 style={{ 23 overflowY: 'scroll', 24 maxHeight: '200px', 25 }} 26 > 27 {Array(100) 28 .fill(null) 29 .map((_item, i) => ( 30 <div key={i} id={`item-${i}`}> 31 item-{i} 32 </div> 33 ))} 34 </div> 35 </> 36 ); 37};
RefObject<HTMLElement>
, container which set as overflow: scroll
, if scroll whole document, pass ref = useRef(document.documentElement)
or useRef(document.body)
.requestAnimationFrame
mode, defaults to 100
, if not provide, speed depends on native API scrollTo
.x
for horizontal or y
for vertical.1
, unit of px
.scrollTo (string|number) => void
number
: the distance to scroll, e.g. scrollTo(400)
string
: the element seletor you want to scrollTo, meanwhile passing to document.querySelector
, e.g. scrollTo('#your-dom-id')
reachedTop boolean
: Whether it has reached the top of refContainer
reachedBottom boolean
: Whether it has reached the bottom of refContainer
Proviede a list
of dom like below, and pass the parent container ref
to hook, it return the scrollbar current state of scrollTop
, curIndex
, curItem
.
1import React, { useRef } from 'react'; 2import { useScrollWatch } from 'react-smooth-scroll-hook'; 3export const ScrollConatainerMode = () => { 4 const ref = useRef(null); 5 const { scrollTop, curIndex, curItem } = useScrollWatch({ 6 ref, 7 list: [ 8 { 9 href: '#item-0', 10 }, 11 { 12 href: '#item-10', 13 }, 14 { 15 href: '#item-20', 16 }, 17 ], 18 }); 19 return ( 20 <> 21 <h2>Scroll Container Mode</h2> 22 <div> 23 <p> 24 <strong>scrollTop:</strong> {scrollTop} 25 </p> 26 <p> 27 <strong>curIndex:</strong> {curIndex} 28 </p> 29 <p> 30 <strong>curHref:</strong> {curItem?.href} 31 </p> 32 </div> 33 <div 34 style={{ 35 padding: '10px', 36 maxHeight: '200px', 37 overflowY: 'scroll', 38 }} 39 ref={ref} 40 > 41 {Array(100) 42 .fill(null) 43 .map((_item, i) => ( 44 <div key={i} id={`item-${i}`}> 45 item-{i} 46 </div> 47 ))} 48 </div> 49 </> 50 ); 51};
Array({href, offset})
: href
is elemet selector string, which passing to querySelector
, such as #element-id
useSmoothScroll
number
: current scrollTop of scroll container.number
: current Index of list{href, offset}
: current Item of listNo vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/24 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
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
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
118 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
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