Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
react-scroll
Advanced tools
The react-scroll package provides smooth scrolling functionality for React applications. It allows developers to create scrollable components and implement smooth scrolling animations to specific elements within a page.
Smooth Scrolling to Elements
This feature allows you to create links that smoothly scroll to specific elements on the page. The 'Link' component is used to create the scrollable link, and the 'Element' component is used to define the target section.
import { Link, Element } from 'react-scroll';
function App() {
return (
<div>
<Link to="section1" smooth={true} duration={500}>Go to Section 1</Link>
<Element name="section1" className="element">
Section 1
</Element>
</div>
);
}
Scroll Events
This feature allows you to register and handle scroll events. You can log or perform actions when scrolling begins or ends. The 'animateScroll' function can be used to programmatically scroll to specific positions.
import { Events, animateScroll as scroll, scroller } from 'react-scroll';
function App() {
useEffect(() => {
Events.scrollEvent.register('begin', function() {
console.log('begin', arguments);
});
Events.scrollEvent.register('end', function() {
console.log('end', arguments);
});
return () => {
Events.scrollEvent.remove('begin');
Events.scrollEvent.remove('end');
};
}, []);
return (
<div>
<button onClick={() => scroll.scrollToTop()}>Scroll to Top</button>
</div>
);
}
Scroll to Top
This feature provides a simple way to scroll to the top of the page programmatically. The 'scrollToTop' function from 'animateScroll' is used to achieve this.
import { animateScroll as scroll } from 'react-scroll';
function App() {
return (
<div>
<button onClick={() => scroll.scrollToTop()}>Scroll to Top</button>
</div>
);
}
The react-router-hash-link package provides smooth scrolling to hash links within a React Router application. It integrates with React Router to enable smooth scrolling to elements identified by hash links. Compared to react-scroll, it is more focused on hash-based navigation within React Router.
The react-scrollable-anchor package allows for smooth scrolling to anchor links within a React application. It provides a simple API to create scrollable anchor links. Compared to react-scroll, it is more focused on anchor-based navigation and does not provide as many customization options.
The react-scrollspy package provides scrollspy functionality for React applications. It allows you to highlight navigation links based on the current scroll position. Compared to react-scroll, it focuses on tracking scroll positions and updating navigation links accordingly.
Directive for basic scrolling and smooth scrolling ( work in progress ) Feel free to contribute - everything is appreciated
$ npm install react-scroll
$ npm install
$ npm run examples
Checkout examples
Basic
var React = require('react');
var Scroll = require('react-scroll');
var Link = Scroll.Link;
var Element = Scroll.Element;
var Section = React.createClass({
render: function () {
return (
<Link to="test1" smooth={true} duration={2000} >Test 1</Link>
<Link to="test2" smooth={true}>Test 2</Link>
<Element name="test1" className="element">
test 1
</Element>
<Element name="test2" className="element">
test 2
</Element>
);
}
});
React.render(
<Section />,
document.getElementById('example')
);
Simply just include the mixins!
var React = require('react');
var Scroll = require('react-scroll');
var Helpers = Scroll.Helpers;
var Element = React.createClass({
mixins: [Helpers.Element],
render: function () {
return (
<div>
{this.props.children}
</div>
);
}
});
var Link = React.createClass({
mixins: [Helpers.Scroll],
render: function () {
return (
<a onClick={this.onClick} href="test">
{this.props.children}
</a>
);
}
});
FAQs
A scroll component for React.js
The npm package react-scroll receives a total of 369,654 weekly downloads. As such, react-scroll popularity was classified as popular.
We found that react-scroll 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.