1.0.0 • Published 5 years ago

react-window-scroll-top v1.0.0

Weekly downloads
6
License
ISC
Repository
github
Last release
5 years ago

react-window-scroll-top

Just a simple component that scrolls view to top of page. npm.io

Installation

npm install --save react-window-scroll-top

Dependencies

  • React ^15.6.1

How To Use

There are two main ways to use the module, either leave standard and pass in props to change the look and functionality, or have in encapsulate children elements and only take care of the scrolling part.

Standard

import React, { Component } from 'react';
import { ScrollTop } from 'react-window-scroll-top';
import './App.css';

class App extends Component {
  render() {
    return (
      <div className="App">
        <header className="App-header">
          <img src="https://somelogo.png" className="App-logo" alt="logo" />
          <h1 className="App-title">Welcome to Our App</h1>
        </header>
        <ScrollTop 
            delay={2} 
            placement="bottom" 
            size="80px"
            text="Scroll up" 
        />
        <p className="App-intro">
          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
          ... lots of text
        </p>
    </div>
  } ...

With Children

import React, { Component } from 'react';
import { ScrollTop } from 'react-window-scroll-top';
import './App.css';

class App extends Component {
  render() {
    return (
      <div className="App">
        <header className="App-header">
          <img src="https://somelogo.png" className="App-logo" alt="logo" />
          <h1 className="App-title">Welcome to React</h1>
        </header>
        <ScrollTop
            delay={2}
        >
            <button>Scroll up</button>
        </ScrollTop>
        <p className="App-intro">
          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
          ... lots of text
        </p>
    </div>
} ...

Properties

PropertyBrief DescriptionExample (*d=default)Data Type
delayIn ms, lower is faster scroll.Delay={15} dNumber
placementBottom or Top of window ( inset set by default at 2vh)placement="bottom" dString
sizeSize of button if using default designsize="80px" dString
scrollOffsetHow far down a user must scroll to show 'scroller' componentscrollOffset={20} dNumber
texttext to display in buttontest="top" dString
stylestyles to apply to button** dcss object

** styles will overwrite predefined defaultStyles with the exception of placement and size