1.0.4 • Published 5 years ago

react-scroll-changer v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

react-scroll-changer

A simple way to do things on scroll.

Demos

Installation

npm install react-scroll-changer

Overview & Basic Example

React Scroll Changer attempts to create an easy component to wrap components and affect them via scroll. A basic setup is something as follows.

app.jsx

import React, { Component } from 'react';
import ScrollChanger from 'react-scroll-changer';

const View = ({ scrollAmount }) => (
  <div
    style={{
      width: "100vw",
      height: "100vh",
      backgroundColor: "#FCD06B",
      opacity: scrollAmount
    }}
  />
);

class App extends Component ({
  render() {
    return (
    <ScrollChanger
      children={<View length={2} />}
      start={1}
      end={0}
      length={2}
    />
    );
  },
});

The ScrollChanger component wraps a seperate view and passes down the scrollAmount function, which is transitions based on the start and end amounts stipulated.

Props

NameTypeRequiredNote
childrenReact ComponentYesThe child element that will be within the scroll changer.
attached (default: true)BooleanYesDoes the child element attach to the viewport on scroll? Or does it scroll naturally.
startNumberYesThe starting value of the scrollAmount.
startOffset (default: 0)NumberYesThe offset in percentage points (eg., 0.3) in which to delay tracking from the top of the viewport.
endNumberYesThe ending value of the scrollAmount.
endOffset (default: 0)NumberYesThe offset in percentage points (eg., 0.3) in which to speed up tracking from the bottom of the viewport.
lengthNumberYesNumber of 100vh blocks to scroll. I.E., a length of 2 is 200vh of scrolling, 3 is 300vh, etc.
styleObjectNoStyle to apply to the inner wrapper
wrapperStyleObjectNoStyle to pass to the wrapper object that encapsulates the whole section
scrollOptionsObjectNoScroll options to send to the below the surface react-scroll-percentage plugin. See the docs for options to pass.

License

MIT