Skip to content

Commit f1171d1

Browse files
committed
update and clarify some notes in docs
1 parent 5ec0e72 commit f1171d1

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

README.md

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# React Scroll Parallax
22

3-
Provides a React component and single global passive scroll listener to add **vertical** scrolling based offsets to elements based on their position in the viewport. Works with universal (server-side rendered) React apps.
3+
Provides a React component and single passive scroll listener to add **vertical** scrolling based offsets to elements based on their position in the viewport. Works with universal (server-side rendered) React apps.
44

55
[View on NPM](https://www.npmjs.com/package/react-scroll-parallax)
66

@@ -22,7 +22,7 @@ npm i react-scroll-parallax --save
2222

2323
Wrap your component tree that will contain `<Parallax />` components with the `<ParallaxProvider />`;
2424

25-
```javascript
25+
```jsx
2626
...
2727
import { ParallaxProvider } from 'react-scroll-parallax';
2828

@@ -58,7 +58,7 @@ import { Parallax } from 'react-scroll-parallax';
5858
</Parallax>
5959
```
6060

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)
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 `parallaxController.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)
6262

6363
## Parallax Component Props
6464

@@ -123,32 +123,32 @@ Optionally pass a tag name to be applied to the outer most parallax element. For
123123

124124
Access the Parallax Controller via context in any components rendered within a `<ParallaxProvider />` by defining the `contextTypes` like so:
125125

126-
```
126+
```jsx
127127
class Foo extends Component {
128128

129129
static contextTypes = {
130130
parallaxController: PropTypes.object.isRequired,
131131
};
132132

133+
doSomething() {
134+
// do stuff with this.context.parallaxController
135+
}
136+
133137
...
134138
```
135139
136-
### Available Methods
137-
138-
Access the following method via context such as `this.context.parallaxController`.
139-
140-
**`update()`**
140+
or for stateless functional components like:
141141
142-
Updates all cached attributes for parallax elements then updates their positions.
143-
144-
**`destroy()`**
145-
146-
Removes window scroll and resize listeners then resets all styles applied to parallax elements.
142+
```jsx
143+
const Bar = (props, context) => (
147144

148-
## Browser Support
145+
// do stuff with context.parallaxController
149146

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.
147+
...
148+
);
151149

150+
Bar.contextTypes = {
151+
parallaxController: PropTypes.object.isRequired,
152152
## Development
153153

154154
Install node modules and start webpack:
@@ -167,6 +167,26 @@ Run Jest tests:
167167

168168
`npm run test`
169169

170+
};
171+
172+
```
173+
174+
### Available Methods
175+
176+
Access the following methods on `parallaxController` via context:
177+
178+
**`update()`**
179+
180+
Updates all cached attributes for parallax elements then updates their positions.
181+
182+
**`destroy()`**
183+
184+
Removes window scroll and resize listeners then resets all styles applied to parallax elements.
185+
186+
## Browser Support
187+
188+
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.
189+
170190
## Optimizations to Reduce Jank
171191
172192
React Scroll Parallax uses a single [passive scroll listener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Improving_scrolling_performance_with_passive_listeners) (dependent on browser support) with the minimal amount of work done on the scroll event to prevent [jank](http://jankfree.org/) (calculations that cause layout, reflow and paint are cached initially and only updated when layout changes). Request animation frame is then used to decouple the scroll handler and further reduce jank. All offsets are applied with 3D transforms to utilize the GPU and prevent paints. If you have ideas to further optimize scrolling please PR or post an issue.

0 commit comments

Comments
 (0)