Skip to content

Commit 5ec0e72

Browse files
committed
update readme with documentation on the ParallaxProvider and parallax controller context access
1 parent 21cf3ea commit 5ec0e72

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

README.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,22 @@ npm i react-scroll-parallax --save
2020

2121
## Usage
2222

23-
Import `ParallaxController` on the client side and call `ParallaxController.init()` to create the global `ParallaxController` on the `window` which will handle controlling all parallax elements on scroll. Ideally, this would be called at the root of your react app on the client.
23+
Wrap your component tree that will contain `<Parallax />` components with the `<ParallaxProvider />`;
2424

2525
```javascript
26-
import { ParallaxController } from 'react-scroll-parallax';
26+
...
27+
import { ParallaxProvider } from 'react-scroll-parallax';
28+
29+
class App extends Component {
30+
render() {
31+
return (
32+
<ParallaxProvider>
33+
<StuffWithParallax />
34+
</ParallaxProvider>
35+
);
36+
}
37+
}
2738

28-
ParallaxController.init();
2939
```
3040

3141
Import the `Parallax` component...
@@ -48,7 +58,7 @@ import { Parallax } from 'react-scroll-parallax';
4858
</Parallax>
4959
```
5060

51-
**NOTE:** `ParallaxController` caches the scroll state and positions of elements on the page for performance reasons. This means that if the page height changes (perhaps from images loading) after `<Parallax />` components are mounted it won't properly determine when the elements are in view. To correct this call the `update()` from the global `ParallaxController` once every thing has loaded and is ready.
61+
**NOTE:** The Parallax Controller caches the scroll state and positions of elements on the page for performance reasons. This means that if the page height changes (perhaps from images loading) after `<Parallax />` components are mounted it won't properly determine when the elements are in view. To correct this you can call the `update()` method from any child component of the `<ParallaxProvider />` via context once every thing has loaded and is ready. More details on how here: [Parallax Controller Context](#parallax-controller-context)
5262

5363
## Parallax Component Props
5464

@@ -109,25 +119,33 @@ Determines whether the scroll rate of the parallax component will move faster or
109119

110120
Optionally pass a tag name to be applied to the outer most parallax element. For example: `<Parallax tag="figure" />`.
111121

112-
## Parallax Controller
122+
## Parallax Controller Context
113123

114-
**`init()`**
124+
Access the Parallax Controller via context in any components rendered within a `<ParallaxProvider />` by defining the `contextTypes` like so:
115125

116-
Initilize the `ParallaxController` on the client with the `init` static method.
126+
```
127+
class Foo extends Component {
128+
129+
static contextTypes = {
130+
parallaxController: PropTypes.object.isRequired,
131+
};
132+
133+
...
134+
```
117135

118-
**NOTE:** Calling `ParallaxController.init()` creates an instance of the controller on the `window` using the same name, e.g. `window.ParallaxController`.
136+
### Available Methods
119137

120-
The following are public methods available on the `window.ParallaxController` global:
138+
Access the following method via context such as `this.context.parallaxController`.
121139

122140
**`update()`**
123141

124142
Updates all cached attributes for parallax elements then updates their positions.
125143

126144
**`destroy()`**
127145

128-
Removes window scroll and resize listeners, resets all styles applied to parallax elements, and sets the global `ParallaxController` to `null`.
146+
Removes window scroll and resize listeners then resets all styles applied to parallax elements.
129147

130-
## Support
148+
## Browser Support
131149

132150
React scroll parallax should support the last two versions of all major browsers and has been tested on desktop Chrome, Firefox, Safari and Edge, as well as the following: iOS 9, iOS 10, Android 4 and IE11. If you encounter any errors for browsers that should be supported please post an issue.
133151

0 commit comments

Comments
 (0)