1.0.0 • Published 3 years ago

react-scroll-up-to-top v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 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

Run npm i react-scroll-to-top

Usage

Import and then include <ScrollToTop /> anywhere in your render/return function:

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

function CoolPage() {
  return (
    <div>
      <ScrollToTop smooth />
      <h1>Hello, world!</h1>
    </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
viewBoxstringThe SVG icon viewBox attribute"0 0 256 256"
componentanyComponent to override SVG icon. See examples
styleObjectObject to add/override styling
classNamestringClassname to completely override styling

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