Skip to content

Commit f632e04

Browse files
committed
update docs
1 parent 092127f commit f632e04

File tree

1 file changed

+50
-15
lines changed

1 file changed

+50
-15
lines changed

docs/parallax-component.md

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,65 @@
11
# \<Parallax>
22

3-
The main component for manipulating a DOM element's position based on it's position within the viewport.
4-
5-
## Example
3+
The main component for applying scroll effects based on an elements position within the viewport.
64

75
```jsx
86
import { Parallax } from 'react-scroll-parallax';
7+
```
8+
9+
## Speed Control
10+
11+
The `speed` prop that will make an element's scroll speed appear to speed up or slow down. This is the simplest way to achieve a parallax effect.
12+
13+
```jsx
14+
const SlowAndFast = () => (
15+
<>
16+
<Parallax speed={-5}>
17+
<div className="slow" />
18+
</Parallax>
19+
<Parallax speed={5}>
20+
<div className="fast" />
21+
</Parallax>
22+
</>
23+
);
24+
```
925

26+
**NOTE:** The `speed` prop simplifies the application of a `translateX` or `translateY` effect based on the `ParallaxController` scroll axis [TODO](#link)
27+
28+
## Translate Controls
29+
30+
If you need more fine tune control of the scroll position you can apply start and end transforms more directly. In this example the element begins with a `translateY(-20%)` and ends with `translateY(10%)`
31+
32+
```jsx
1033
const VerticalParallax = () => (
11-
<Parallax y={[-20, 20]}>
34+
<Parallax y={[-20, 10]}>
1235
<div className="my-thing" />
1336
</Parallax>
1437
);
1538
```
1639

17-
## Parallax Props
40+
**NOTE:** Translate values without units default to `%` so `-20` becomes `-20%`.
41+
42+
## Props
43+
44+
All props for creating effects are defined by a _start_ and _end_ value represented by an `array` -- for example: `[start, end]`.
45+
46+
- The _start_ of an effect begins when the element's original position enters the viewport -- the top of the element enters the bottom of the view.
47+
- The _end_ of an effect begins when the element's original position exits the viewport -- the bottom of the element exits the top of the view.
1848

1949
The following are all props that can be passed to the `<Parallax>` component:
2050

21-
| Name | Type | Default | Description |
22-
| -------------- | :----------------------: | :------- | ------------------------------------------------------------------------------------------------------------------------------------- |
23-
| **x** | `string[]` or `number[]` | `[0, 0]` | Start and end translation on x-axis in `%` or `px`. If no unit is passed percent is assumed. Percent is based on the elements width. |
24-
| **y** | `string[]` or `number[]` | `[0, 0]` | Start and end translation on y-axis in `%` or `px`. If no unit is passed percent is assumed. Percent is based on the elements height. |
25-
| **className** | `string` | | Optionally pass additional class names to be added to the outermost parallax element. |
26-
| **disabled** | `boolean` | `false` | Disables parallax effects on individual elements when `true`. |
27-
| **styleInner** | `object` | | Optionally pass a style object to be added to the innermost parallax element. |
28-
| **styleOuter** | `object` | | Optionally pass a style object to be added to the outermost parallax element. |
29-
| **tagInner** | `string` | `div` | Optionally pass an element tag name to be applied to the innermost parallax element. |
30-
| **tagOuter** | `string` | `div` | Optionally pass an element tag name to be applied to the outermost parallax element. |
51+
| Name | Type | Default | Description |
52+
| -------------- | :----------------------: | :------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
53+
| **speed** | `number` | | A value representing the elements scroll speed. If less than zero scroll will appear slower. If greater than zero scroll will appear faster. |
54+
| **x** | `string[]` or `number[]` | | Start and end translation on x-axis in `%` or `px`. If no unit is passed percent is assumed. Percent is based on the elements width. |
55+
| **y** | `string[]` or `number[]` | | Start and end translation on y-axis in `%` or `px`. If no unit is passed percent is assumed. Percent is based on the elements height. |
56+
| **rotate** | `string[]` or `number[]` | | Start and end rotation on z-axis in `deg`, `rad`, or `turn`. If no unit is passed `deg` is assumed. |
57+
| **rotateX** | `string[]` or `number[]` | | Start and end rotation on x-axis in `deg`, `rad`, or `turn`. If no unit is passed `deg` is assumed. |
58+
| **rotateY** | `string[]` or `number[]` | | Start and end rotation on y-axis in `deg`, `rad`, or `turn`. If no unit is passed `deg` is assumed. |
59+
| **rotateZ** | `string[]` or `number[]` | | Start and end rotation on z-axis in `deg`, `rad`, or `turn`. If no unit is passed `deg` is assumed. |
60+
| **className** | `string` | | Optionally pass additional class names to be added to the outermost parallax element. |
61+
| **disabled** | `boolean` | `false` | Disables parallax effects on individual elements when `true`. |
62+
| **styleInner** | `object` | | Optionally pass a style object to be added to the innermost parallax element. |
63+
| **styleOuter** | `object` | | Optionally pass a style object to be added to the outermost parallax element. |
64+
| **tagInner** | `string` | `div` | Optionally pass an element tag name to be applied to the innermost parallax element. |
65+
| **tagOuter** | `string` | `div` | Optionally pass an element tag name to be applied to the outermost parallax element. |

0 commit comments

Comments
 (0)