You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-11Lines changed: 29 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,12 +20,22 @@ npm i react-scroll-parallax --save
20
20
21
21
## Usage
22
22
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 />`;
@@ -48,7 +58,7 @@ import { Parallax } from 'react-scroll-parallax';
48
58
</Parallax>
49
59
```
50
60
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)
52
62
53
63
## Parallax Component Props
54
64
@@ -109,25 +119,33 @@ Determines whether the scroll rate of the parallax component will move faster or
109
119
110
120
Optionally pass a tag name to be applied to the outer most parallax element. For example: `<Parallax tag="figure" />`.
111
121
112
-
## Parallax Controller
122
+
## Parallax Controller Context
113
123
114
-
**`init()`**
124
+
Access the Parallax Controller via context in any components rendered within a `<ParallaxProvider />` by defining the `contextTypes` like so:
115
125
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
+
```
117
135
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
119
137
120
-
The following are public methods available on the `window.ParallaxController` global:
138
+
Access the following method via context such as `this.context.parallaxController`.
121
139
122
140
**`update()`**
123
141
124
142
Updates all cached attributes for parallax elements then updates their positions.
125
143
126
144
**`destroy()`**
127
145
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.
129
147
130
-
## Support
148
+
## Browser Support
131
149
132
150
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.
0 commit comments