3.0.0 • Published 2 years ago

react-scroll-to-top v3.0.0

Weekly downloads
1,139
License
MIT
Repository
github
Last release
2 years ago

react-scroll-to-top

A lightweight and customizable button component that scrolls to the top of a page when pressed
The button is only visible once a certain height has been reached on the page

NPM

Live demo

A live demo can be found here

Installation

With npm:

npm i react-scroll-to-top

or with Yarn:

yarn add react-scroll-to-top

Usage

Import and then add <ScrollToTop /> at the bottom of your return function (for a11y reasons):

import ScrollToTop from "react-scroll-to-top";

function CoolPage() {
  return (
    <div>
      <h1>Hello, world!</h1>
      <div style={{ marginTop: "150vh" }} />
      <ScrollToTop smooth />
    </div>
  );
}

Props

PropTypeDescriptionDefault
smoothbooleanWhether to use smooth scrolling*false
topnumberHeight after page scroll to be visible20
colorstringThe SVG icon fill color"black"
svgPathstringThe SVG icon path d attributeAn arrow path
widthstringThe SVG icon width"28"
heightstringThe SVG icon height"28"
viewBoxstringThe SVG icon viewBox attribute"0 0 256 256"
componentanyComponent to override SVG icon. See examples
styleObjectObject to add/override styling
classNamestringClassname to add/override styling (note, !important for overrides might be needed)

Smooth scrolling uses a newer window.scrollTo implementation.\ Check out its support in browsers at MDN web docs.

Examples

With custom SVG path
With custom SVG component
With custom DOM element

Types

Written in TypeScript, no need for @types installation

2.0.3-beta.2

2 years ago

2.0.3-beta.1

2 years ago

2.0.3-beta.0

2 years ago

1.0.9

2 years ago

2.0.4-beta.0

2 years ago

2.0.2

2 years ago

2.0.4

2 years ago

2.0.0-beta

2 years ago

3.0.0

2 years ago

2.0.1-beta

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.2.4

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.0

4 years ago