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: documentation/docs/usage/components/parallax-banner-component.md
+54-29Lines changed: 54 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,13 @@ sidebar_position: 3
4
4
5
5
# ParallaxBanner
6
6
7
-
Component that utilizes `<Parallax>` components to achieve a parallaxing banner effect. Allows a single or multiple images to be parallaxed at different rates within the banner area.
7
+
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.
8
8
9
-
## Basic Example
9
+
### Working Demos
10
+
11
+
See some example [code with demos](/docs/examples/banners).
12
+
13
+
## Examples
10
14
11
15
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.
12
16
@@ -18,19 +22,17 @@ Use the `layers` to supply a `speed` and `image` to your banner. In this case, i
18
22
speed:-20,
19
23
},
20
24
]}
21
-
style={{
22
-
height:'500px',
23
-
}}
25
+
style={{ aspectRatio:'2 / 1' }}
24
26
/>
25
27
```
26
28
27
29
:::caution
28
30
29
-
You **must**add a `height` value either as a `style` or through a `className`otherwise the banner will have no height and be hidden.
31
+
You **must**define a style that gives the root `<div>`a `height` value otherwise the banner will have no height and be hidden. This can be through a `style`, through a `className`, or other method of styling.
30
32
31
33
:::
32
34
33
-
## Multiple Layers
35
+
###Multiple Layers
34
36
35
37
Supply the `layers` prop with additional configuration for more images. Each layer can contain unique configurations.
36
38
@@ -46,15 +48,19 @@ Supply the `layers` prop with additional configuration for more images. Each lay
46
48
speed:-10,
47
49
},
48
50
]}
49
-
style={{
50
-
height:'500px',
51
-
}}
51
+
style={{ aspectRatio:'2 / 1' }}
52
52
/>
53
53
```
54
54
55
-
## Customized Layers
55
+
:::caution
56
+
57
+
**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.
58
+
59
+
:::
60
+
61
+
### Customized Layers
56
62
57
-
Supply the `layers` prop with [additional configuration](#banner-layers-prop) for more images. Each layer can contain unique configurations.
63
+
You can pass your own markup or components to the `children` property of a `layer`.
58
64
59
65
```jsx
60
66
<ParallaxBanner
@@ -68,31 +74,50 @@ Supply the `layers` prop with [additional configuration](#banner-layers-prop) fo
68
74
speed:-10,
69
75
},
70
76
]}
71
-
style={{
72
-
height:'500px',
73
-
}}
77
+
style={{ aspectRatio:'2 / 1' }}
74
78
/>
75
79
```
76
80
77
81
## Props
78
82
79
83
The following are all props that can be passed to the `<ParallaxBanner>` component:
|**disabled**|`boolean`| Disables _all_ parallax layers when enabled. |
88
+
|**layers**|`array`| An `array` of `objects` with layer properties: [see layer props below](/docs/usage/components/parallax-banner-component#banner-layers-prop)|
89
+
|`...rest`|`HTMLDivElement`| All other properties are spread to the `<div>`. |
90
+
91
+
:::info
92
+
93
+
All other props are defined on the root `div` element.
The `layers` prop takes an array of objects that will represent each image (or custom children) of the parallax banner. The following properties describe a layer object:
103
+
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:
|**children**|`ReactElement`|| Custom layer children provided as a React element, for example `<Video />`|
108
+
|**expanded**|`boolean`|`true`| Indicate if the layer should be expanded with negative top/bottom margins so the edges will never be visible. |
109
+
|**image**|`string`|| Image source that will be applied as a CSS `background-image` on the layer set to `cover`. |
110
+
|`...rest`|`ParallaxElementConfig`|| All known parallax props will be passed to `useParallax`. [See all the parallax props](https://parallax-controller.vercel.app/docs/usage/props) that this hook will accept. All other properties are spread to the `<div>` representing the layer. |
|**speed**|`number`|| A value from `-1` to `1` that represents the vertical offset to be applied to the current layer, `0.1` would equal a `10%` offset on the top and bottom. |
95
-
|**children**|`ReactElement`|| Custom layer children provided as a React element, for example `<Video />`|
96
-
|**expanded**|`boolean`|`true`| Indicate if the layer should be expanded with negative top/bottom margins so the edges will never be visible. |
97
-
|**image**|`string`|| Image source that will be applied as a CSS background image on the layer. |
98
-
|**props**|`object`|| Props to apply to the layer element. Example: `{ props: style: { background: 'red' }}`|
0 commit comments