Skip to content

Commit 591768d

Browse files
committed
document ParallaxBanner in readme
1 parent 7085a97 commit 591768d

File tree

1 file changed

+70
-15
lines changed

1 file changed

+70
-15
lines changed

README.md

Lines changed: 70 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ Provides a React component and single passive scroll listener to add **vertical*
88

99
Some links demonstrating possible effects created with this lib:
1010

11-
- [Example Site](https://jscottsmith.github.io/react-scroll-parallax-examples/examples/parallax-example/)
12-
- [Parallax Testing](https://jscottsmith.github.io/react-scroll-parallax-examples/examples/parallax-test/)
13-
- [CodePen Parallax](https://codepen.io/jscottsmith/pen/eREbwz)
14-
- [CodePen Parallax Banner](https://codepen.io/jscottsmith/pen/aVBvGj)
11+
* [Example Site](https://jscottsmith.github.io/react-scroll-parallax-examples/examples/parallax-example/)
12+
* [Parallax Testing](https://jscottsmith.github.io/react-scroll-parallax-examples/examples/parallax-test/)
13+
* [CodePen Parallax](https://codepen.io/jscottsmith/pen/eREbwz)
14+
* [CodePen Parallax Banner](https://codepen.io/jscottsmith/pen/aVBvGj)
1515

1616
## Install
1717

@@ -29,7 +29,7 @@ yarn add react-scroll-parallax
2929

3030
## Usage
3131

32-
The [`<ParallaxProvider />`](#parallaxprovider) should wrap the component tree that contains all `<Parallax />` components. This should be a top level component like `<AppContainer />`. For example:
32+
The [`<ParallaxProvider>`](#parallaxprovider) should wrap the component tree that contains all `<Parallax>` components. This should be a top level component like `<AppContainer>`. For example:
3333

3434
```jsx
3535
import { ParallaxProvider } from 'react-scroll-parallax';
@@ -43,7 +43,6 @@ class AppContainer extends Component {
4343
);
4444
}
4545
}
46-
4746
```
4847

4948
Import the `Parallax` component and use it anywhere within the provider like so:
@@ -66,25 +65,81 @@ const ParallaxImage = () => (
6665

6766
**NOTE:** Scroll state and positions of elements on the page are cached for performance reasons. This means that if the page height changes (most likely from [images loading](#example-usage-of-context)) after `<Parallax />` components are mounted the controller won't properly determine when the elements are in view. To correct this you can call the `parallaxController.update()` method from any child component of the `<ParallaxProvider />` via `context`. More details on how here: [Parallax Controller Context](#parallax-controller-context).
6867

69-
## \<Parallax> Props
68+
## \<Parallax>
69+
70+
The main component for manipulating an element's position based on scroll position within the viewport.
71+
72+
### Props
7073

71-
The following are all props that can be passed to the React `<Parallax />` component:
74+
The following are all props that can be passed to the `<Parallax>` component:
7275

7376
| Name | Type | Default | Description |
7477
| -------------------- | :------------------: | :------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
75-
| **className** | `String` | | Optionally pass additional class names to be added to the outer most parallax element. |
78+
| **className** | `String` | | Optionally pass additional class names to be added to the outermost parallax element. |
7679
| **disabled** | `Boolean` | `false` | Determines if the component will have parallax offsets applied. If `true` parallax styles are completely removed from the element and it is no longer updated. |
7780
| **offsetXMax** | `Number` or `String` | `0` | Maximum **x** offset in `%` or `px`. If no unit is passed percent is assumed. Percent is based on the elements width. |
7881
| **offsetXMin** | `Number` or `String` | `0` | Minimum **x** offset in `%` or `px`. If no unit is passed percent is assumed. Percent is based on the elements width. |
7982
| **offsetYMax** | `Number` or `String` | `0` | Maximum **y** offset in `%` or `px`. If no unit is passed percent is assumed. Percent is based on the elements height. |
8083
| **offsetYMin** | `Number` or `String` | `0` | Minimum **y** offset in `%` or `px`. If no unit is passed percent is assumed. Percent is based on the elements height. |
8184
| **slowerScrollRate** | `Boolean` | `false` | Internally swaps the min/max offset y values of the parallax component to give the appearance of moving faster or slower than the default rate of scroll. |
82-
| **styleInner** | `Object` | | Optionally pass a style object to be added to the innermost parallax element |
83-
| **styleOuter** | `Object` | | Optionally pass a style object to be added to the outermost parallax element |
85+
| **styleInner** | `Object` | | Optionally pass a style object to be added to the innermost parallax element. |
86+
| **styleOuter** | `Object` | | Optionally pass a style object to be added to the outermost parallax element. |
8487
| **tag** | `String` | `div` | Optionally pass an element tag name to be applied to the outermost parallax element. |
8588

89+
## \<ParallaxBanner>
90+
91+
Component that utilizes `<Parallax>` components to achieve a parallaxing banner effect.
92+
93+
### Example Usage
94+
95+
Use the `layers` prop to indicate all images, offset amounts and scroll rates. Optionally pass additional children to be rendered. Styles of the outermost banner element can also be changed. Here's an example:
96+
97+
```jsx
98+
<ParallaxBanner
99+
className="your-class"
100+
layers={[
101+
{
102+
image: 'https://foo.com/foo.jpg',
103+
amount: 0.1,
104+
slowerScrollRate: false,
105+
},
106+
{
107+
image: 'https://foo.com/bar.jpg',
108+
amount: 0.2,
109+
slowerScrollRate: false,
110+
},
111+
]}
112+
style={{
113+
height: '500px',
114+
}}
115+
>
116+
<h1>Banner Children</h1>
117+
</ParallaxBanner>
118+
```
119+
120+
### Props
121+
122+
The following are all props that can be passed to the `<ParallaxBanner>` component:
123+
124+
| Name | Type | Default | Description |
125+
| ------------- | :-------: | :------ | ------------------------------------------------------------------------------------------------------------------------------ |
126+
| **className** | `String` | | Optionally pass additional class names to be added to the outermost parallax banner element. |
127+
| **disabled** | `Boolean` | `false` | Determines if the components internal parallax layers will have parallax offsets applied. |
128+
| **layers** | `Array` | | A required `Array` of `Objects` with correct layer properties: `[{ amount: 0.1, image: 'foo.jpg', slowerScrollRate: false }]`. |
129+
| **style** | `Object` | | Optionally pass a style object to be added to the outermost parallax banner element. |
130+
131+
### Layers Prop
132+
133+
The `layers` props takes an array of objects that will represent each image of the parallax banner. The following properties describe a layer:
134+
135+
| Name | Type | Description |
136+
| -------------------- | :------: | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
137+
| **amount** | `Number` | A value from `0 – 1` that represents the vertical offset to be applied to the current layer, `0.1` would equal a `10%` offset on the top and bottom. |
138+
| **image** | `String` | Image source that will be applied as a CSS background image on the layer. |
139+
| **slowerScrollRate** | `Number` | Indicates whether the layer should move faster or slower than the default rate of scroll. |
140+
86141
## \<ParallaxProvider>
87-
142+
88143
The `<ParallaxProvider />` component is meant to wrap a top level component in your application and is necessary to provide access though React's context API to the parallax controller. This component should only be used once in you app, for instance in an `<AppContainer />` component that won't be mounted/unmounted during route changes. Like so:
89144

90145
```jsx
@@ -93,13 +148,13 @@ const AppContainer = () => (
93148
<Router>
94149
<App />
95150
</Router>
96-
</ParallaxProvider>
151+
</ParallaxProvider>
97152
);
98153
```
99154

100155
### Parallax Controller Context
101156

102-
Access the Parallax Controller via [React context](https://facebook.github.io/react/docs/context.html) in any components rendered within a `<ParallaxProvider />` by defining the `contextTypes` like so:
157+
Access the Parallax Controller via [React context](https://facebook.github.io/react/docs/context.html) in any components rendered within a `<ParallaxProvider>` by defining the `contextTypes` like so:
103158

104159
```jsx
105160
class Foo extends Component {
@@ -109,7 +164,7 @@ class Foo extends Component {
109164

110165
doSomething() {
111166
// do stuff with this.context.parallaxController
112-
}
167+
}
113168
}
114169
```
115170

0 commit comments

Comments
 (0)