Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
react-scrollable-url
Advanced tools
Lightweight library for smooth scrolling ulrls and anchors in React.
npm install --save react-scrollable-url
To run examples locally, npm run example
, then open your
browser to localhost:3210.
Use the ScrollableSection
tag to wrap any React element(s), making it a scrollable anchor.
Use the ScrollableLink
to wrpar a link to the corresponding section.
You may also set a title
attribute if you want to update a document title.
import React, { Component } from 'react';
import ScrollableSection, { ScrollableLink } from 'react-scrollable-url';
export default class Page extends Component {
render() {
return (
<div>
<ScrollableLink href="/section1">
<a> Go to section 1 </a>
</ScrollableLink>
<ScrollableLink href="/section2">
<a> Go to section 2 </a>
</ScrollableLink>
<ScrollableSection name={'section1'} title="Section 1">
<div> Hello World </div>
</ScrollableSection>
<ScrollableSection name={'section2'} title="Section 2">
<div> How are you world? </div>
</ScrollableSection>
</div>
)
}
}
In this case the address will be changed to /section1
and /section2
.
You can also use hashes or combine path and hash updates:
<ScrollableLink href="#panel1">
<a> Go to panel 1 </a>
</ScrollableLink>
<ScrollableLink href="#panel2">
<a> Go to panel 2 </a>
</ScrollableLink>
<ScrollableSection hash={'panel1'}>
<div> Panel 1 </div>
</ScrollableSection>
<ScrollableSection hash={'panel2'}>
<div> Panel 2 </div>
</ScrollableSection>
<ScrollableLink href="/section1#surprise">
<a> Go to section 1, section #surprise</a>
</ScrollableLink>
<ScrollableLink href="/section1#nothing">
<a> Go to section 1, section #nothing </a>
</ScrollableLink>
<ScrollableSection name={'section1'} hash={'surprise'}>
<div> Surprise </div>
</ScrollableSection>
<ScrollableSection name={'section1'} hash={'nothing'}>
<div> Nothing </div>
</ScrollableSection>
You can also use exact
prop if you want ot replace whole path with the given name/anchor.
<ScrollableSection name={'section1'} exact>
<div> Content </div>
</ScrollableSection>
Access configureAnchors to customize scrolling and anchors.
import { configureAnchors } from 'react-scrollable-url'
// Offset all anchors by -60 to account for a fixed header
// and scroll more quickly than the default 400ms
configureAnchors({offset: 60})
option | default | description |
---|---|---|
offset | 0 | Offset from top on scrolling to the section. Can be used if you have a sticky header. |
keepLastAnchorHash | false | Keep last anchor hash |
debounce | 100 | Debouce the scroll event |
scrollDelay | 0 | Delay between page load and scrolling to the corresponding section |
scrollBehaviour | 'smooth' | Can be 'smooth' , 'instant' and 'auto' |
scrollOnImagesLoad | false | Wait until all the images are loaded before scrolling to the section on page load |
A small toolkit of scrolling utilies for use with anchors
import { goToTop } from 'react-scrollable-url'
// scroll to top of the page
goToTop()
Please open issues on Github. Issues are easier to address if you include context and code samples.
Please contribute!
FAQs
Provide smooth scrolling link and anchors in React.
We found that react-scrollable-url demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.