npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-scroll-backdrop

v1.0.1

Published

React scroll backdrop is a context based React component that transitions/animates the background one user scroll.

Downloads

5

Readme

react-scroll-backdrop

npm version npm downloads

react-scroll-backdrop is a Context API based react component that provides a smooth animation/transition fade-in between color and image backdrops

On component mount, backdrop transition zones will registered their location on the page. As the window scrolls to a specified window scroll position it will scan for backdrop zones to reach that point & trigger backdrop color/images. A zone will remain active as long as the scroll position is within the body of the backdrop zone component

Demo

Install

$ npm install --save react-scroll-backdrop

Usage

Compositional pattern

Common use case using just BackdropContainer and BackdropZone as parent/child

import { BackdropContainer, ColorBackdrop, ImageBackdrop } from 'react-scroll-backdrop';


const defaultValue = {
  value: '#fff',
  type: 'color'
};

<BackdropContainer fromTop={350} defaultValue={defaultValue}>

  <ColorBackdrop value='#CD9CAE' theme='dark'>
    // ...
  </ColorBackdrop>

  // perhaps some other components in between

  <ImageBackdrop value='assets/bridge.jpg' theme='light'>
    // ...
  </ImageBackdrop>

</BackdropContainer>

Function as a child pattern

Function as children pattern can be used with the BackdropZone to access positional arguments that can be useful when rendering child components to create different states/events.

import { ColorBackdrop, ImageBackdrop } from 'react-scroll-backdrop';

<BackdropContainer>

  <ColorBackdrop value="#414953" theme="light">
    {( active, value, theme ) => <GraySkies isActive={active} theme={currentTheme} />}
  </ColorBackdrop>

  // ...or

  <ImageBackdrop value="#414953" theme="light">
    {( active, value, theme ) => <GraySkies isActive={active} theme={currentTheme} />}
  </ImageBackdrop>

</BackdropContainer>

( active, )

Type: boolean

Default: false

will trigger true when the BackdropZone is in scroll position

( , value )

Type: { type: 'color' | 'image', value: string }

will trigger a new backdrop value throughout all backdrop zones when a backdropZone is in scroll position

( , , theme )

Type: string

will trigger a new theme string value throughout all backdrop zones when a backdropZone is in scroll position

BackdropContainer Props

defaultValue

Type: { type: 'image' | 'color', value: string }

When the scroll position is not at an indicated backdrop zone scroll position the backdrop container background will transition to the default values

for color type. value property accepts any css background-color value

const DefaultColorValues = {
  value: '#dedede',
  type: 'color',
};

<BackdropContainer defaultValue={DefaultColorValues}>

for image type. value property accepts an asset path string

const DefaultImageValues = {
  value: '../assets/water.jpg',
  type: 'image',
};

<BackdropContainer defaultValue={DefaultImageValues}>

animationDuration

Type: number

default: 600

Animation duration in milliseconds that will be applied to all animation/transitions in between zones

fromTop

Type: number

Default: 0

The value of fromTop is used as the scroll position in pixels that will be used to check for and trigger backdrop color/image transitions. When a BackdropZone component reaches 100px from viewport top, for example, it will trigger that BackdropZone's color/image value.

ColorBackdrop & ImageBackdrop Props

value

Type: string

Default: undefined

Color backdrop: any acceptable CSS background-color value Image backdrop: Asset path to image. Accepts any image type acceptable to modern browsers

theme

Type: string

Default: 'default'

Theme names are completely arbitrary names that you can provide to backdrop zones. Theme names are registered to a color zone and are triggered when a zone becomes active. When a zone becomes active the theme name is sent to all other backdrop zones and will also available in the backdrop context. Use themes for rendering and events. Ex. change font & UI colors.

instant

Type: boolean

Default: false

Because the react-scroll-backdrop is triggered by user scroll, there are going to be times when there is no backdrop color/image because the user hasn't started scrolling. It will remain that way until a scroll in a backdrop zone is triggered. If you need a color/image to be triggered instantly you can provide this prop to the backdrop zone that you would like to trigger instantly.

off

Type: boolean

Default: false

In cases in which react-scroll-backdrop is used in a dynamic environment (Ex. CMS powered builds) you might have use cases in which you might want to have the option to turn a particular zone off. Providing the off property with a value of true prevents the backdrop zone from registering.