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
-[Optimizations to Reduce Jank](#optimizations-to-reduce-jank)
44
+
-[PSA](#psa)
45
45
46
46
## Usage
47
47
48
-
The [`<ParallaxProvider>`](#parallaxprovider)should wrap the component tree that contains all `<Parallax>` components. This should be a top level component like `<AppContainer>`. For example:
48
+
The [`<ParallaxProvider>`](#parallaxprovider)must wrap the component tree that contains all `<Parallax>` components. This should be a top level component like `<App>`. For example:
Import the `Parallax` component and use it anywhere within the provider like so:
64
+
Then import the `Parallax` component and use it anywhere within the provider. Here's an example that will transform the element on the `y` axis starting at `-20%` and ending at `20%` (`y = [-20, 20]`\*percent is assumed with no provided unit).
Example with transforms on the `x` axis starting at `-100px` and ending at `200px` (`x = ['-100px', '200px']`).
77
+
78
+
```jsx
79
+
import { Parallax } from'react-scroll-parallax';
80
+
81
+
constHorizontalParallax= () => (
82
+
<Parallax x={['-100px', '200px']}>
83
+
<div className="my-thing"/>
84
+
</Parallax>
73
85
);
74
86
```
75
87
@@ -107,22 +119,22 @@ Use the `layers` prop to indicate all images, offset amounts, and scroll rates.
107
119
108
120
```jsx
109
121
<ParallaxBanner
110
-
className="your-class"
111
-
layers={[
112
-
{
113
-
image:'https://foo.com/foo.jpg',
114
-
amount:0.1,
115
-
},
116
-
{
117
-
image:'https://foo.com/bar.png',
118
-
amount:0.2,
119
-
},
120
-
]}
121
-
style={{
122
-
height:'500px',
123
-
}}
122
+
className="your-class"
123
+
layers={[
124
+
{
125
+
image:'https://foo.com/foo.jpg',
126
+
amount:0.1,
127
+
},
128
+
{
129
+
image:'https://foo.com/bar.png',
130
+
amount:0.2,
131
+
},
132
+
]}
133
+
style={{
134
+
height:'500px',
135
+
}}
124
136
>
125
-
<h1>Banner Children</h1>
137
+
<h1>Banner Children</h1>
126
138
</ParallaxBanner>
127
139
```
128
140
@@ -155,11 +167,11 @@ The `<ParallaxProvider />` component is meant to wrap a top level component in y
155
167
156
168
```jsx
157
169
constAppContainer= () => (
158
-
<ParallaxProvider>
159
-
<Router>
160
-
<App />
161
-
</Router>
162
-
</ParallaxProvider>
170
+
<ParallaxProvider>
171
+
<Router>
172
+
<App />
173
+
</Router>
174
+
</ParallaxProvider>
163
175
);
164
176
```
165
177
@@ -174,38 +186,18 @@ The following props configure the `<ParallaxProvider>` component:
174
186
175
187
### Parallax Controller Context
176
188
177
-
Access the controller via [React context](https://facebook.github.io/react/docs/context.html) in any components rendered within a `<ParallaxProvider>` by using the `withController()` HOC:
Access the controller via [React context](https://facebook.github.io/react/docs/context.html) in any components rendered within a `<ParallaxProvider>`.
182
190
183
-
classMyComponentextendsComponent {
184
-
static propTypes = {
185
-
parallaxController:PropTypes.object,
186
-
};
187
-
188
-
doSomething() {
189
-
const { parallaxController } =this.props;
190
-
// do stuff with `parallaxController`
191
-
}
192
-
}
193
-
194
-
// Compose your component with the Higher Order Component
195
-
exportwithController(MyComponent);
196
-
197
-
```
198
-
199
-
Also `parallaxController` is accessible using `useController()`[React hook](https://reactjs.org/docs/hooks-intro.html) in components without writing a class or wrapping them in HOC.
191
+
This is accessible by using `useController()`[React hook](https://reactjs.org/docs/hooks-intro.html) in components without writing a class or wrapping them in HOC.
@@ -226,35 +218,31 @@ Removes window scroll and resize listeners then resets all styles applied to par
226
218
The most common use case that would require access to the controller is dealing with images. Since the controller caches attributes for performance they will need to be updated with the correct values once the image loads. Here's an example of how you could do that with an `<Image />` component:
If your parallax components are stuck and acting weird, this is most likely due to the fact that your page initial scroll was not at the top on load. Here's a possible solution to this problem using `useController()` hook. It can be used in your application top level component or specifically in the part of your application where you are experiencing problems.
0 commit comments