1.2.0 • Published 3 years ago

react-appear-on-scroll v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

react-appear-on-scroll

Minimalistic package providing containers which appears when scrolled into view

NPM JavaScript Style Guide

Install

npm install --save react-appear-on-scroll

Example

Examples can be seen here.

Requirements

If you wrap a React Class Component or Functional Component with the <AppearingContainer/> you have to pass an inputRef prop to it's child (See example below)

Usage

import React, { Component } from 'react'
import 'react-appear-on-scroll/dist/index.css'

import {
  AppearingContainer,
  AppearSequentialContainer
} from 'react-appear-on-scroll'
import 'react-appear-on-scroll/dist/index.css'

// Wrapping a regular element
class Example extends Component {
  render() {
    return (
      <AppearingContainer
        animationType='fromLeft'
        transitionType='bouncy'
        fading
        stayVisible
      >
        <div style={{ width: '200px', height: '150px' }}>
          <p>This container will appear once it's entirely in the viewport</p>
        </div>
      </AppearingContainer>
    )
  }
}

//Wrapping a React Functional Component
const TestComponent = ({ inputRef }) => {
  return (
    <div ref={inputRef}>
      <p>Hello!</p>
    </div>
  )
}

class Example extends Component {
  render() {
    return (
      <AppearingContainer
        animationType='fromLeft'
        transitionType='bouncy'
        fading
        stayVisible
      >
        <TestComponent />
      </AppearingContainer>
    )
  }
}

// Using the AppearSequentialContainer
class Example2 extends Component {
  render() {
    return (
      <AppearSequentialContainer>
        <AppearingContainer
          animationType='scale'
          transitionType='bouncy'
          fading
          stayVisible
        >
          <div style={{ width: '200px', height: '150px' }}>
            <p>This container will appear first</p>
          </div>
        </AppearingContainer>
        <AppearingContainer
          animationType='scale'
          transitionType='bouncy'
          fading
          stayVisible
        >
          <div style={{ width: '200px', height: '150px' }}>
            <p>This container will appear with a 200ms delay</p>
          </div>
        </AppearingContainer>
        <AppearingContainer
          animationType='scale'
          transitionType='bouncy'
          fading
          stayVisible
        >
          <div style={{ width: '200px', height: '150px' }}>
            <p>This container will appear with a 400ms delay</p>
          </div>
        </AppearingContainer>
      </AppearSequentialContainer>
    )
  }
}

Props

AppearingContainer

PropType:DefaultValue
parentStylingobjectnoneCustom styling which is applied to the parent container
wrapperStylingobjectnoneCustom styling which is applied to the content wrapper
delaynumbernoneAdds transition-delay, utilized by AppearSequentialContainer
transitionTypestring'ease'One of 'ease', 'smooth' or 'bouncy'
fadingboolfalseif true: transitions opacity from 0 to 1 over 0.5s
stayVisibleboolfalseif true: transitions once and is then left visible
requireFullHeightToRenderboolfalseif true: does not render until entire element is visible in the viewport, else it renders when half the element is visible
animationTypestring'fromLeft'One of 'fromLeft', 'fromRight', 'fromTop', 'fromBottom' or 'scale'
containerPaddingnumber15Adds padding to the parent container, necessary if box-shadow is used

AppearSequentialContainer

PropTypeDefaultValue
childrenelement or array of elementsnoneOne or more 'AppearingContainer'
styleobjectnoneCustom styling which is applied to the parent container
delayIncrementnumber100Number of milliseconds of delay between each transition

License

MIT © hugobergqvist

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago