react-scroll vs react-perfect-scrollbar vs react-custom-scrollbars vs react-scrollbar-size vs rc-scrollbars
React Scroll Libraries Comparison
1 Year
react-scrollreact-perfect-scrollbarreact-custom-scrollbarsreact-scrollbar-sizerc-scrollbarsSimilar Packages:
What's React Scroll Libraries?

These libraries provide customizable scrollbar components for React applications, enhancing the user experience by allowing developers to create visually appealing and functional scrollbars. They help in managing overflow content, improving accessibility, and providing a consistent look across different browsers and devices. Each library has unique features and design principles that cater to different use cases and developer preferences.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
react-scroll521,0454,381139 kB2317 days agoMIT
react-perfect-scrollbar175,287486-605 years agoMIT
react-custom-scrollbars145,2343,217-2207 years agoMIT
react-scrollbar-size15,9642816.9 kB15-MIT
rc-scrollbars10,939152363 kB172 years agoMIT
Feature Comparison: react-scroll vs react-perfect-scrollbar vs react-custom-scrollbars vs react-scrollbar-size vs rc-scrollbars

Customization Options

  • react-scroll:

    react-scroll does not focus on scrollbar customization but rather on providing smooth scrolling effects for navigation. It allows developers to create scrollable sections that enhance user experience during navigation.

  • react-perfect-scrollbar:

    react-perfect-scrollbar allows for some level of customization, but it focuses more on providing a consistent and functional scrollbar experience rather than extensive styling options. It is suitable for developers who want a good-looking scrollbar without the need for deep customization.

  • react-custom-scrollbars:

    react-custom-scrollbars provides extensive customization capabilities, including the ability to style every part of the scrollbar (thumb, track, etc.) using CSS. This library is perfect for developers looking to create unique scrollbar designs that match their application's theme.

  • react-scrollbar-size:

    react-scrollbar-size does not offer customization for scrollbar appearance but provides functionality to detect scrollbar sizes, which can be used to adjust layouts accordingly.

  • rc-scrollbars:

    rc-scrollbars offers basic customization options, allowing developers to change colors and sizes of the scrollbar components easily. However, it is less flexible compared to others when it comes to advanced styling.

Performance

  • react-scroll:

    react-scroll is lightweight and focuses on providing smooth scrolling functionality, making it a performant choice for single-page applications. It does not add significant overhead to the application.

  • react-perfect-scrollbar:

    react-perfect-scrollbar is designed to be lightweight and efficient, providing a good balance between functionality and performance. It is suitable for applications that require smooth scrolling without sacrificing speed.

  • react-custom-scrollbars:

    While react-custom-scrollbars offers rich features, it may introduce some performance overhead due to its extensive customization capabilities. Developers should be mindful of this when using it in performance-sensitive applications.

  • react-scrollbar-size:

    As a utility library, react-scrollbar-size is very lightweight and does not impact the performance of the application. It is designed to work seamlessly without introducing any noticeable lag.

  • rc-scrollbars:

    This library is optimized for performance, making it a good choice for applications where speed and responsiveness are critical. It has a minimal footprint and does not introduce significant overhead.

Ease of Use

  • react-scroll:

    react-scroll is easy to use for implementing smooth scrolling effects, especially for those familiar with React. Its API is intuitive, allowing for quick integration into projects.

  • react-perfect-scrollbar:

    react-perfect-scrollbar is user-friendly and easy to set up, making it suitable for developers who want a quick and efficient solution without delving into complex configurations.

  • react-custom-scrollbars:

    react-custom-scrollbars has a moderate learning curve due to its extensive customization options. Developers may need to invest time to fully utilize its capabilities, but it provides great flexibility once mastered.

  • react-scrollbar-size:

    react-scrollbar-size is very easy to use, providing a simple API for measuring scrollbar sizes. It requires minimal setup and can be quickly integrated into any application.

  • rc-scrollbars:

    rc-scrollbars is straightforward to implement, making it an excellent choice for developers who want a simple solution without a steep learning curve. Its API is easy to understand and integrate into existing projects.

Browser Compatibility

  • react-scroll:

    react-scroll is compatible with modern browsers and is designed to work seamlessly with React applications, ensuring smooth scrolling functionality across platforms.

  • react-perfect-scrollbar:

    react-perfect-scrollbar is compatible with most modern browsers, making it a safe choice for applications that need to support a broad range of users.

  • react-custom-scrollbars:

    react-custom-scrollbars provides good browser compatibility, but developers should test their custom styles across different browsers to ensure consistent behavior and appearance.

  • react-scrollbar-size:

    react-scrollbar-size is compatible with all modern browsers and does not introduce any compatibility issues, making it a reliable utility for measuring scrollbar sizes.

  • rc-scrollbars:

    rc-scrollbars is designed to work across modern browsers, ensuring a consistent experience for users regardless of the platform they are using. It is a reliable choice for applications targeting a wide audience.

Community and Support

  • react-scroll:

    react-scroll has a growing community, and its documentation is clear and helpful, making it easy for developers to implement and troubleshoot scrolling features.

  • react-perfect-scrollbar:

    react-perfect-scrollbar has a decent community and support, with sufficient documentation to help developers get started and troubleshoot common issues.

  • react-custom-scrollbars:

    react-custom-scrollbars has a larger community and more resources available, including documentation and examples, making it easier for developers to find help and support when needed.

  • react-scrollbar-size:

    react-scrollbar-size has a smaller community, but it is straightforward enough that most developers can implement it without needing extensive support.

  • rc-scrollbars:

    rc-scrollbars has a smaller community compared to some of the other libraries, which may result in fewer resources and examples available for troubleshooting and support.

How to Choose: react-scroll vs react-perfect-scrollbar vs react-custom-scrollbars vs react-scrollbar-size vs rc-scrollbars
  • react-scroll:

    Use react-scroll if you are looking for a library that not only provides scrollbars but also offers smooth scrolling capabilities for navigating between sections of a page. This is particularly useful for single-page applications or websites with a lot of content that needs to be navigated easily.

  • react-perfect-scrollbar:

    Select react-perfect-scrollbar if you want a straightforward solution that provides a perfect scrollbar experience with minimal configuration. It is great for projects that require a balance between functionality and ease of use, especially for mobile-friendly applications.

  • react-custom-scrollbars:

    Opt for react-custom-scrollbars if you require extensive customization options and a rich set of features, including the ability to create complex scrollbar designs. This package is suitable for applications that need a high degree of control over the scrollbar appearance and behavior.

  • react-scrollbar-size:

    Choose react-scrollbar-size if your primary concern is measuring the size of scrollbars for layout adjustments. This library is useful when you need to ensure that your application layout adapts dynamically based on the presence of scrollbars.

  • rc-scrollbars:

    Choose rc-scrollbars if you need a lightweight solution that offers a simple API for customizing scrollbars without heavy dependencies. It is ideal for projects where performance is a priority and minimalism is desired.

README for react-scroll

React Scroll

React component for animating vertical scrolling

Table of Contents

Introduction

React-Scroll is a lightweight library for enhancing scrolling functionality in React applications. Whether you're building a single-page application, a portfolio site, or a complex web application, React Scroll provides you with an easy-to-use solution for implementing smooth scrolling behavior. This works with the latest versions of Google Chrome, Microsodt Edge, and Firefox.

React-Scroll AI Bot

React-Scroll Bot will help you understand this repository better. You can ask for code examples, installation guide, debugging help and much more.

Features

  • Smooth Scrolling: Achieve seamless scrolling animations between sections of your web page.
  • Customization: Customize scroll behavior to suit your application's design and user experience requirements.
  • Accessibility: Ensure your scrolling functionality is accessible to all users, including those who rely on assistive technologies.
  • Lightweight: Keep your bundle size small with React Scroll's minimal footprint.

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

Code example

Next.js

Example of Using react-scroll with image and detailed explanation!

In this example, the react-scroll library was utilized to enable smooth scrolling navigation within a single-page React application. The library provides components such as Link and Element that facilitate seamless navigation between different sections of the page. Once you start your react app, you can add this code at the bottom to experience the scroll feature!

Code:

import React from 'react';
import { Link, Element } from 'react-scroll';

function App() {
  return (
    <div>
      <nav>
        <ul>
          <li>
            <Link to="section1" smooth={true} duration={500}>Section 1</Link>
          </li>
          <li>
            <Link to="section2" smooth={true} duration={500}>Section 2</Link>
          </li>
          {/* Add more navigation links as needed */}
        </ul>
      </nav>
      <Element name="section1">
        <section style={{ height: '100vh', backgroundColor: 'lightblue' }}>
          <h1>Section 1</h1>
          <p>This is the content of section 1</p>
        </section>
      </Element>
      <Element name="section2">
        <section style={{ height: '100vh', backgroundColor: 'lightgreen' }}>
          <h1>Section 2</h1>
          <p>This is the content of section 2</p>
        </section>
      </Element>
      {/* Add more sections with Element components as needed */}
    </div>
  );
}

export default App;

GIF_example

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

Best Practices and Tips

  • Optimize performance by limiting the number of elements with scroll events.
  • Test your application on various devices and screen sizes to ensure accessibility.

Troubleshooting and FAQs

  • Q: How do I customize the scroll behavior?

  • A: You can customize the scroll duration, easing function, and other parameters using the duration, smooth, and offset props.

  • Q: Why is my smooth scrolling not working? This can be applied to any prop!

  • A: Ensure that the smooth prop is set to true and that your browser supports smooth scrolling.

Contributions

  • To contribute to React-Scroll, please follow these guidelines:

  • Fork the repository and create a new branch for your changes.

  • Make your changes and submit a pull request with a clear description of your work.

  • Include tests and ensure all existing tests pass before submitting your changes.

Changelog

License

  • React Scroll is licensed under the MIT License. Explore this to understand terms and conditions of the license- https://opensource.org/licenses/MIT