Which is Better React Scroll Libraries?
react-scroll vs react-scroll-parallax vs react-scrollspy vs react-anchor-link-smooth-scroll vs react-scrollable-anchor
1 Year
react-scrollreact-scroll-parallaxreact-scrollspyreact-anchor-link-smooth-scrollreact-scrollable-anchorSimilar Packages:
What's React Scroll Libraries?

These libraries provide various functionalities for smooth scrolling, scroll animations, and scroll-based interactions in React applications. They enhance user experience by enabling smooth transitions between sections, parallax effects, and dynamic scroll tracking, making them essential tools for modern web development.

NPM Package Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
react-scroll468,3664,352134 kB230a year agoMIT
react-scroll-parallax61,7232,871200 kB8a year agoMIT
react-scrollspy46,489427-844 years agoMIT
react-anchor-link-smooth-scroll21,02124332.5 kB20-MIT
react-scrollable-anchor12,506291-48-MIT
Feature Comparison: react-scroll vs react-scroll-parallax vs react-scrollspy vs react-anchor-link-smooth-scroll vs react-scrollable-anchor

Smooth Scrolling

  • react-scroll: React-scroll offers smooth scrolling capabilities along with customizable duration and easing functions. It allows developers to create smooth transitions to different sections of a page, making it suitable for more complex scrolling needs.
  • react-scroll-parallax: While primarily focused on parallax effects, react-scroll-parallax also supports smooth scrolling for elements that move at different speeds, creating a dynamic visual experience as users scroll through the page.
  • react-scrollspy: React-scrollspy does not focus on smooth scrolling but rather on tracking the scroll position to highlight active sections. It can be combined with smooth scrolling libraries to enhance the overall experience.
  • react-anchor-link-smooth-scroll: This package provides a simple way to create smooth scrolling effects for anchor links. It allows you to link to specific sections of your page with a smooth transition, enhancing the user experience without additional configuration.
  • react-scrollable-anchor: This package provides basic smooth scrolling for anchor links, ensuring that users can navigate to different sections of a page seamlessly. It is straightforward and easy to use, making it suitable for simple projects.

Parallax Effects

  • react-scroll: React-scroll does not provide built-in parallax effects, but it can be integrated with other libraries to achieve such effects if needed.
  • react-scroll-parallax: This library excels in creating parallax scrolling effects, allowing different elements to move at varying speeds relative to the scroll position. It is designed specifically for this purpose, making it the best choice for parallax animations.
  • react-scrollspy: React-scrollspy does not support parallax effects but can be used alongside other libraries that do.
  • react-anchor-link-smooth-scroll: This package does not support parallax effects as its primary focus is on smooth scrolling for anchor links.
  • react-scrollable-anchor: This package does not include parallax effects, focusing solely on anchor link functionality.

Ease of Use

  • react-scroll: React-scroll offers a moderate learning curve with more features to configure. While it is user-friendly, it may require additional understanding of its API for more advanced use cases.
  • react-scroll-parallax: This library has a slightly steeper learning curve due to its focus on parallax effects, but it is well-documented, making it accessible for developers willing to invest time in learning its features.
  • react-scrollspy: React-scrollspy is easy to use, especially for developers familiar with React. It requires basic setup and can be integrated into existing navigation systems without much hassle.
  • react-anchor-link-smooth-scroll: This package is very easy to use, with minimal setup required. It allows developers to implement smooth scrolling with just a few lines of code, making it ideal for beginners.
  • react-scrollable-anchor: This package is straightforward and easy to implement, making it suitable for quick projects where minimal configuration is desired.

Performance

  • react-scroll: React-scroll is efficient but may require optimization for complex applications with many scrollable sections to maintain performance.
  • react-scroll-parallax: This library is designed for performance, but implementing multiple parallax effects can impact rendering speed if not managed properly. It is essential to optimize the number of elements using parallax effects to maintain smooth performance.
  • react-scrollspy: React-scrollspy is efficient in tracking scroll positions and highlighting active sections without significant performance overhead.
  • react-anchor-link-smooth-scroll: This package is lightweight and optimized for performance, ensuring that smooth scrolling does not hinder the overall performance of the application.
  • react-scrollable-anchor: This package is lightweight and performs well for basic anchor scrolling needs, ensuring minimal impact on application performance.

Customization

  • react-scroll: This package offers extensive customization options, allowing developers to configure duration, easing functions, and scroll behavior, making it suitable for tailored experiences.
  • react-scroll-parallax: React-scroll-parallax provides various customization options for parallax effects, including speed and direction of movement, allowing for highly tailored visual experiences.
  • react-scrollspy: React-scrollspy allows for some customization in terms of the active class and scroll thresholds, making it adaptable to different navigation designs.
  • react-anchor-link-smooth-scroll: Customization options are limited to basic smooth scrolling settings, making it straightforward but less flexible for advanced use cases.
  • react-scrollable-anchor: Customization is minimal, focusing on basic anchor link functionality without extensive options for configuration.
How to Choose: react-scroll vs react-scroll-parallax vs react-scrollspy vs react-anchor-link-smooth-scroll vs react-scrollable-anchor
  • react-scroll: Opt for react-scroll if you want a more comprehensive solution that includes features like scroll events, scroll-to functionality, and the ability to create scrollable sections. This package is great for applications that require more control over scrolling behavior and animations.
  • react-scroll-parallax: Select react-scroll-parallax if you are looking to implement parallax scrolling effects in your application. This package is specifically designed for creating visually appealing backgrounds and elements that move at different speeds during scrolling, enhancing the overall aesthetic of your site.
  • react-scrollspy: Choose react-scrollspy if you want to implement scroll tracking and navigation highlighting. This package is perfect for applications with multiple sections where you want to indicate the current section in a navigation menu as the user scrolls.
  • react-anchor-link-smooth-scroll: Choose this package if you need simple and effective smooth scrolling for anchor links. It is lightweight and easy to implement, making it ideal for single-page applications or sections of a page that require smooth transitions.
  • react-scrollable-anchor: Use react-scrollable-anchor if you need a straightforward way to manage anchor links and scroll behavior without additional features. This package is suitable for projects that require basic anchor link functionality without the overhead of more complex libraries.
README for react-scroll

React Scroll

React component for animating vertical scrolling

Install

$ npm install react-scroll

or

$ yarn add react-scroll

Run

$ npm install
$ npm test
$ npm start

or

$ yarn
$ yarn test
$ yarn start

Examples

Checkout examples

Live example

Basic

Basic-Keydown

Container

With-hash

With-overflow

Code

Usage

import React, { useEffect } from 'react';
import { Link, Button, Element, Events, animateScroll as scroll, scrollSpy } from 'react-scroll';

const Section = () => {

  // useEffect is used to perform side effects in functional components.
  // Here, it's used to register scroll events and update scrollSpy when the component mounts.
  useEffect(() => {
    
    // Registering the 'begin' event and logging it to the console when triggered.
    Events.scrollEvent.register('begin', (to, element) => {
      console.log('begin', to, element);
    });

    // Registering the 'end' event and logging it to the console when triggered.
    Events.scrollEvent.register('end', (to, element) => {
      console.log('end', to, element);
    });

    // Updating scrollSpy when the component mounts.
    scrollSpy.update();

    // Returning a cleanup function to remove the registered events when the component unmounts.
    return () => {
      Events.scrollEvent.remove('begin');
      Events.scrollEvent.remove('end');
    };
  }, []);

  // Defining functions to perform different types of scrolling.
  const scrollToTop = () => {
    scroll.scrollToTop();
  };

  const scrollToBottom = () => {
    scroll.scrollToBottom();
  };

  const scrollTo = () => {
    scroll.scrollTo(100); // Scrolling to 100px from the top of the page.
  };

  const scrollMore = () => {
    scroll.scrollMore(100); // Scrolling an additional 100px from the current scroll position.
  };

  // Function to handle the activation of a link.
  const handleSetActive = (to) => {
    console.log(to);
  };

  // Rendering the component's JSX.
  return (
  <div>
    {/* Link component to scroll to "test1" element with specified properties */}
    <Link 
      activeClass="active" 
      to="test1" 
      spy={true} 
      smooth={true} 
      offset={50} 
      duration={500} 
      onSetActive={handleSetActive}
    >
      Test 1
    </Link>

    {/* Other Link and Button components for navigation, each with their unique properties and targets */}
    {/* ... */}

    {/* Element components that act as scroll targets */}
    <Element name="test1" className="element">
      test 1
    </Element>
    <Element name="test2" className="element">
      test 2
    </Element>
    <div id="anchor" className="element">
      test 6 (anchor)
    </div>

    {/* Links to elements inside a specific container */}
    <Link to="firstInsideContainer" containerId="containerElement">
      Go to first element inside container
    </Link>
    <Link to="secondInsideContainer" containerId="containerElement">
      Go to second element inside container
    </Link>

    {/* Container with elements inside */}
    <div className="element" id="containerElement">
      <Element name="firstInsideContainer">
        first element inside container
      </Element>
      <Element name="secondInsideContainer">
        second element inside container
      </Element>
    </div>

    {/* Anchors to trigger scroll actions */}
    <a onClick={scrollToTop}>To the top!</a>
    <br/>
    <a onClick={scrollToBottom}>To the bottom!</a>
    <br/>
    <a onClick={scrollTo}>Scroll to 100px from the top</a>
    <br/>
    <a onClick={scrollMore}>Scroll 100px more from the current position!</a>
  </div>
);

};

export default Section;


Props/Options

activeClass class applied when element is reached
activeStyle style applied when element is reached
to Target to scroll to
containerId Container to listen for scroll events and to perform scrolling in
spy Make Link selected when scroll is at its targets position
hashSpy Update hash based on spy, containerId has to be set to scroll a specific element
smooth Animate the scrolling
offset Scroll additional px ( like padding )
duration time of the scroll animation - can be a number or a function (`function (scrollDistanceInPx) { return duration; }`), that allows more granular control at run-time
delay Wait x milliseconds before scroll
isDynamic In case the distance has to be recalculated - if you have content that expands etc.
onSetActive Invoke whenever link is being set to active
onSetInactive Invoke whenever link is lose the active status
ignoreCancelEvents Ignores events which cancel animated scrolling
horizontal Whether to scroll vertically (`false`) or horizontally (`true`) - default: `false`
spyThrottle Time of the spy throttle - can be a number

Full example

<Link activeClass="active"
      to="target"
      spy={true}
      smooth={true}
      hashSpy={true}
      offset={50}
      duration={500}
      delay={1000}
      isDynamic={true}
      onSetActive={this.handleSetActive}
      onSetInactive={this.handleSetInactive}
      ignoreCancelEvents={false}
      spyThrottle={500}
>
  Your name
</Link>

Scroll Methods

Scroll To Top

import { animateScroll } from 'react-scroll';

const options = {
  // your options here, for example:
  duration: 500,
  smooth: true,
};

animateScroll.scrollToTop(options);

Scroll To Bottom

import { animateScroll } from 'react-scroll';

const options = {
  // Your options here, for example:
  duration: 500,
  smooth: true,
};

animateScroll.scrollToBottom(options);

Scroll To (position)

import { animateScroll } from 'react-scroll';

const options = {
  // Your options here, for example:
  duration: 500,
  smooth: true,
};

// Scroll to 100 pixels from the top of the page
animateScroll.scrollTo(100, options);


Scroll To (Element)

animateScroll.scrollTo(positionInPixels, props = {});

import { Element, scroller } from 'react-scroll';

<Element name="myScrollToElement"></Element>

// Somewhere else, even another file
scroller.scrollTo('myScrollToElement', {
  duration: 1500,
  delay: 100,
  smooth: true,
  containerId: 'ContainerElementID',
  offset: 50, // Scrolls to element + 50 pixels down the page
  // ... other options
});

Scroll More (px)

import { animateScroll } from 'react-scroll';

const options = {
  // Your options here, for example:
  duration: 500,
  smooth: true,
};

// Scroll an additional 10 pixels down from the current scroll position
animateScroll.scrollMore(10, options);

Scroll events

begin - start of the scrolling

import { Events } from 'react-scroll';

Events.scrollEvent.register('begin', function(to, element) {
  console.log('begin', to, element);
});

end - end of the scrolling/animation


import { Events } from 'react-scroll';

Events.scrollEvent.register('end', function(to, element) {
  console.log('end', to, element);
});

Remove events

import { Events } from 'react-scroll';

Events.scrollEvent.remove('begin');
Events.scrollEvent.remove('end');

Create your own Link/Element

Simply just pass your component to one of the high order components (Element/Scroll)

import React from 'react';
import { ScrollElement, ScrollLink } from 'react-scroll';

const Element = (props) => {
  return (
    <div {...props} ref={(el) => { props.parentBindings.domNode = el; }}>
      {props.children}
    </div>
  );
};

export const ScrollableElement = ScrollElement(Element);

const Link = (props) => {
  return (
    <a {...props}>
      {props.children}
    </a>
  );
};

export const ScrollableLink = ScrollLink(Link);

Scroll Animations

Add a custom easing animation to the smooth option. This prop will accept a Boolean if you want the default, or any of the animations listed below

import { scroller } from 'react-scroll';

scroller.scrollTo('myScrollToElement', {
  duration: 1500,
  delay: 100,
  smooth: 'easeInOutQuint',
  containerId: 'ContainerElementID',
  // ... other options
});

List of currently available animations:

linear
	- no easing, no acceleration.
easeInQuad
	- accelerating from zero velocity.
easeOutQuad
	- decelerating to zero velocity.
easeInOutQuad
	- acceleration until halfway, then deceleration.
easeInCubic
	- accelerating from zero velocity.
easeOutCubic
	- decelerating to zero velocity.
easeInOutCubic
	- acceleration until halfway, then deceleration.
easeInQuart
	- accelerating from zero velocity.
easeOutQuart
	- decelerating to zero velocity.
easeInOutQuart
	-  acceleration until halfway, then deceleration.
easeInQuint
	- accelerating from zero velocity.
easeOutQuint
	- decelerating to zero velocity.
easeInOutQuint
	- acceleration until halfway, then deceleration.

A good visual reference can be found at easings.net

Changelog