3.5.1 • Published 2 years ago

react-parallax v3.5.1

Weekly downloads
26,792
License
MIT
Repository
github
Last release
2 years ago

react-parallax NPM version

Install

yarn add react-parallax

Demo on codesandbox

Contribute

If you find any bug or have problems and/or ideas regarding this library feel free to open an issue or pull request. Either way please create a working example so I can reproduce it. Link to a repository or even easier - fork the demo codesandbox project. This would help a lot.

This project is maintained during evenings and weekends. If you like it, please consider to buy me a coffee ;-) ...or contribute in other ways.

Usage examples

Basic - background image with fixed blur effect

import { Parallax } from 'react-parallax';

const Container = () => (
    <Parallax blur={10} bgImage="path/to/image.jpg" bgImageAlt="the cat" strength={200}>
        Content goes here. Parallax height grows with content height.
    </Parallax>
);

Dynamic blur and negative strength for reverse direction

import { Parallax, Background } from 'react-parallax';

const Container = () => (
    <Parallax
        blur={{ min: -15, max: 15 }}
        bgImage={require('path/to/another/image.jpg')}
        bgImageAlt="the dog"
        strength={-200}
    >
        Blur transition from min to max
        <div style={{ height: '200px' }} />
    </Parallax>
);

Custom background element

Use the background component for custom elements. Unlike the bgImage this one will not be scaled depending on the parent/window width.

import { Parallax, Background } from 'react-parallax';

const Container = () => (
    <Parallax strength={300}>
        <Background className="custom-bg">
            <img src="http://www.fillmurray.com/500/320" alt="fill murray" />
        </Background>
    </Parallax>
);

Render prop

Calculate your own stuff depending on the percentage value.

import { Parallax, Background } from 'react-parallax';

const Container = () => (
    <Parallax
        bgImage="/path/to/another/image"
        renderLayer={percentage => (
            <div
                style={{
                    position: 'absolute',
                    background: `rgba(255, 125, 0, ${percentage * 1})`,
                    left: '50%',
                    top: '50%',
                    width: percentage * 500,
                    height: percentage * 500,
                }}
            />
        )}
    >
        <p>... Content</p>
    </Parallax>
);

Background Component

Child nodes inside this Background will be positioned like the bgImage behind the other children. Unlike the bgImage there is no automatic scaling.

Props

NameTypeDefaultDescriptionexample
bgImageStringpath to the background image that makes parallax effect
bgImageAltStringalt text for bgImage.
bgImageSizeStringimg sizes attribute.
bgImageSrcSetStringimg srcset attribute
styleObjectstyle object for the component itself
bgStyleObjectadditional style object for the bg image/children Valid style attributes
bgClassNameStringcustom classname for image
contentClassNameStringreact-parallax-contentcustom classname for parallax inner
bgImageStyleObjectset background image styling{height: '50px', maxWidth: '75px', opacity: '.5'}
strengthNumber100parallax effect strength (in pixel). this will define the amount of pixels the background image is translated
blurNumber0 or {min:0, max:5}number value for background image blur or object in format {min:0, max:5} for dynamic blur depending on scroll position
renderLayerFunctionFunction that gets a percentage value of the current position as parameter for custom calculationa. It renders a layer above the actual background, below children.renderLayer={percentage => (<div style={{ background:`rgba(255, 125, 0, ${percentage * 1})`}}/> )}
disabledBooleanfalseturns off parallax effect if set to true{height: '50px', maxWidth: '75px', opacity: '.5'}
classNameStringset an additional className
parentNodedocumentset optional parent for nested scrolling
childrenused to display any content inside the react-parallax component

Development

# setup
yarn
# Development, live reload, JSX transpiling, run:
yarn dev

Port 3000 on all OS by default. Can be set with option -port=8080

License

MIT

3.4.0

2 years ago

3.5.1

2 years ago

3.5.0

2 years ago

3.3.0

3 years ago

3.2.1

3 years ago

3.2.0

3 years ago

3.1.2

4 years ago

3.1.1

4 years ago

3.0.4-rc.0

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.2.4

5 years ago

3.0.0-rc2

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.1

6 years ago

1.8.1

6 years ago

2.0.0

6 years ago

1.8.0

6 years ago

1.7.0

6 years ago

1.6.2

6 years ago

1.6.1

6 years ago

1.6.0

6 years ago

1.5.1

6 years ago

1.5.0

7 years ago

1.4.4

7 years ago

1.4.3

7 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.8

7 years ago

1.2.7

7 years ago

1.2.6

7 years ago

1.2.5

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.5

7 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.4.5

8 years ago

0.4.4

8 years ago

0.4.3

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

9 years ago

0.1.7

9 years ago

0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago