Skip to content

Commit a9829d0

Browse files
committed
docs: update documentation for ParallaxBannerLayer usage
1 parent 1c84ec7 commit a9829d0

File tree

1 file changed

+85
-12
lines changed

1 file changed

+85
-12
lines changed

documentation/docs/usage/components/parallax-banner-component.md

Lines changed: 85 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ sidebar_position: 3
77
Component that sets up layers of `useParallax` elements to achieve a parallaxing banner. Enables the layering of images, or custom markup, with scroll effects in a container that hides overflow.
88

99
```tsx
10-
import { ParallaxBanner } from 'react-scroll-parallax';
10+
import { ParallaxBanner, ParallaxBannerLayer } from 'react-scroll-parallax';
1111
```
1212

1313
### Working Demos
@@ -16,6 +16,23 @@ See some example [code with demos](/docs/examples/banners).
1616

1717
## Examples
1818

19+
There are two ways to setup a banner:
20+
21+
1. You can use the `<ParallaxBanner>` [`layers`](#with-the-layers-prop) prop.
22+
2. You can define [`ParallaxBannerLayer`](#example-with-the-parallaxbannerlayer) as the `<ParallaxBanner>` children.
23+
24+
### Example with the ParallaxBannerLayer
25+
26+
Use the `ParallaxBannerLayer` component to define the `speed` and `image` for your banner. In this case, it will create a banner using a single image, that moves slower than the rate of scroll, and the edges of the image will never be visible.
27+
28+
```jsx
29+
<ParallaxBanner style={{ aspectRatio: '2 / 1' }}>
30+
<ParallaxBannerLayer image="https://foo.com/foo.jpg" speed={-20} />
31+
</ParallaxBanner>
32+
```
33+
34+
### Example with the layers prop
35+
1936
Use the `layers` to supply a `speed` and `image` to your banner. In this case, it will create a banner using a single image, that moves slower than the rate of scroll, and the edges of the image will never be visible.
2037

2138
```jsx
@@ -36,7 +53,16 @@ You **must** define a style that gives the root `<div>` a `height` value otherwi
3653

3754
:::
3855

39-
### Multiple Layers
56+
### Creating Multiple Layers
57+
58+
Define multiple Banner layer children with independent prop configurations.
59+
60+
```jsx
61+
<ParallaxBanner style={{ aspectRatio: '2 / 1' }}>
62+
<ParallaxBannerLayer image="https://foo.com/foo.jpg" speed={-20} />
63+
<ParallaxBannerLayer image="https://foo.com/bar.jpg" speed={-10} />
64+
</ParallaxBanner>
65+
```
4066

4167
Supply the `layers` prop with additional configuration for more images. Each layer can contain unique configurations.
4268

@@ -58,13 +84,24 @@ Supply the `layers` prop with additional configuration for more images. Each lay
5884

5985
:::caution
6086

61-
**Layer order matters.** First element in the the array will appear on the bottom of the stacking context; last layer of the array will appear on top.
87+
**Layer order matters.** First element in the the array or children will appear on the bottom of the stacking context; last layer of the array or children will appear on top.
6288

6389
:::
6490

65-
### Customized Layers
91+
### Custom Layer Markup
6692

67-
You can pass your own markup or components to the `children` property of a `layer`.
93+
This example defines a headline in the second layer.
94+
95+
```jsx
96+
<ParallaxBanner style={{ aspectRatio: '2 / 1' }}>
97+
<ParallaxBannerLayer image="https://foo.com/foo.jpg" speed={-20} />
98+
<ParallaxBannerLayer>
99+
<h1>My Headline</h1>
100+
</ParallaxBannerLayer>
101+
</ParallaxBanner>
102+
```
103+
104+
You can also pass your own markup or components to the `children` property when using `layers`.
68105

69106
```jsx
70107
<ParallaxBanner
@@ -82,15 +119,31 @@ You can pass your own markup or components to the `children` property of a `laye
82119
/>
83120
```
84121

122+
### Using a Custom Image Element
123+
124+
You don't need to use the `image` prop and can instead pass your own `img`, `picture`, `video` or custom image component. Use this if you need to use accessible images, custom image components, or other `img` attributes like `srcSet` or `loading`.
125+
126+
```jsx
127+
<ParallaxBanner style={{ aspectRatio: '2 / 1' }}>
128+
<ParallaxBannerLayer speed={-20}>
129+
<img
130+
src="https://foo.com/sahara.jpg"
131+
alt="Sahara Desert landscape"
132+
loading="lazy"
133+
/>
134+
</ParallaxBannerLayer>
135+
</ParallaxBanner>
136+
```
137+
85138
## Props
86139

87140
The following are all props that can be passed to the `<ParallaxBanner>` component:
88141

89-
| Name | Type | Description |
90-
| ------------ | :--------------: | ------------------------------------------------------------------------------------------------------------------------------------------- |
91-
| **disabled** | `boolean` | Disables _all_ parallax layers when enabled. |
92-
| **layers** | `array` | An `array` of `objects` with layer properties: [see layer props below](/docs/usage/components/parallax-banner-component#banner-layers-prop) |
93-
| `...rest` | `HTMLDivElement` | All other properties are spread to the `<div>`. |
142+
| Name | Type | Description |
143+
| ------------ | :--------------: | -------------------------------------------------------------------------------------------------------------------------- |
144+
| **disabled** | `boolean` | Disables _all_ parallax layers when enabled. |
145+
| **layers** | `array` | Optional `array` of layers -- [see layer props below](/docs/usage/components/parallax-banner-component#banner-layers-prop) |
146+
| `...rest` | `HTMLDivElement` | All other properties are spread to the `<div>`. |
94147

95148
:::info
96149

@@ -102,7 +155,9 @@ All other props are defined on the root `div` element.
102155

103156
:::
104157

105-
## Banner Layers Prop
158+
## Banner Layer Props
159+
160+
The `ParallaxBannerLayer` the following configuration as props.
106161

107162
The `layers` prop takes an array of objects that represent each image (or custom children) of the parallax banner. The following properties describe a layer object:
108163

@@ -113,11 +168,29 @@ The `layers` prop takes an array of objects that represent each image (or custom
113168
| **image** | `string` | | Image source that will be applied as a CSS `background-image` on the layer set to `cover`. |
114169
| `...rest` | `ParallaxElementConfig` | | All known parallax props will be passed to `useParallax`. [See all the parallax props](/docs/usage/parallax-props) that this hook will accept. All other properties are spread to the `<div>` representing the layer. |
115170

171+
### Example Using ParallaxBannerLayer
172+
173+
```jsx
174+
<ParallaxBanner>
175+
<ParallaxBannerLayer
176+
expanded={false}
177+
speed={-10}
178+
scale={[1, 1.2]}
179+
opacity={[0.9, 1]}
180+
>
181+
<img src="foo" />
182+
</ParallaxBannerLayer>
183+
</ParallaxBanner>
184+
```
185+
186+
### Example Using the Layers Prop
187+
116188
```jsx
117189
<ParallaxBanner
118190
layers={[
119191
{
120-
children: <div />,
192+
children: <img src="foo" />,
193+
expanded: false,
121194
speed: -10,
122195
scale: [1, 1.2],
123196
opacity: [0.9, 1],

0 commit comments

Comments
 (0)