Skip to content

Commit bdb3e0d

Browse files
committed
docs: add exmples usage of ParallaxBanners
1 parent 8edc0fd commit bdb3e0d

File tree

5 files changed

+190
-1
lines changed

5 files changed

+190
-1
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
sidebar_position: 2
3+
---
4+
5+
import { ParallaxBannerImages } from '/src/components/parallax-banner-images';
6+
import { ParallaxBannerWithHeadline } from '/src/components/parallax-banner-with-headline';
7+
import { ParallaxBannerEmbedHeadline } from '/src/components/parallax-banner-embed-headline';
8+
9+
# Parallax Banners
10+
11+
The following demonstrates some common usage of the [`<ParallaxBanner>`](/docs/usage/components/parallax-banner-component) component.
12+
13+
## Example with Multiple Layers
14+
15+
This example uses two layers, one background and one foreground. The order of the defined layer determines the stacking of the each image: First in the array will appear at the back and be covered by subsequent layers.
16+
17+
The `image` prop defines the layer image.
18+
The `speed` prop is used to make the layer move at it's own pace.
19+
20+
The foreground `speed` is defined so that it will move faster than the background:
21+
22+
```tsx
23+
import { ParallaxBanner } from 'react-scroll-parallax';
24+
25+
const Component = () => {
26+
return (
27+
<ParallaxBanner
28+
layers={[
29+
{ image: '/static/banner-background.jpg', speed: -20 },
30+
{ image: '/static/banner-foreground.png', speed: -10 },
31+
]}
32+
className="ratio-2/1"
33+
/>
34+
);
35+
};
36+
```
37+
38+
:::info
39+
40+
For the most _natural_ visual effect make the layer `speed` depend on the distance of the image: the closer the items in the image the **faster** they should move; the further away the **slower** they should move.
41+
42+
:::
43+
44+
<ParallaxBannerImages />
45+
46+
## Example with a headline
47+
48+
By defining `children` you can add any markup for a headline or any other custom elements. In the following example the headline is positioned absolutely over each banner layer.
49+
50+
```tsx
51+
import { ParallaxBanner } from 'react-scroll-parallax';
52+
53+
const Component = () => {
54+
return (
55+
<ParallaxBanner
56+
layers={[
57+
{ image: '/static/banner-background.jpg', speed: -20 },
58+
{ image: '/static/banner-foreground.png', speed: -10 },
59+
]}
60+
className="ratio-2/1"
61+
>
62+
<div className="absolute inset-0 flex items-center justify-center">
63+
<h1 className="text-8xl text-white font-thin">Hello World!</h1>
64+
</div>
65+
</ParallaxBanner>
66+
);
67+
};
68+
```
69+
70+
<ParallaxBannerWithHeadline />
71+
72+
## Embed the headline in the scene
73+
74+
You can take the effect even further by embedding the headline in the scene. This can be done by defining another layer and assigning the markup to the `children` of that layer.
75+
76+
```tsx
77+
import { ParallaxBanner } from 'react-scroll-parallax';
78+
79+
const Component = () => {
80+
return (
81+
<ParallaxBanner
82+
layers={[
83+
{ image: '/static/banner-background.jpg', speed: -20 },
84+
{
85+
speed: -12,
86+
children: (
87+
<div className="absolute inset-0 flex items-center justify-center">
88+
<h1 className="text-8xl text-white font-thin">Hello World!</h1>
89+
</div>
90+
),
91+
},
92+
{ image: '/static/banner-foreground.png', speed: -10 },
93+
]}
94+
className="ratio-2/1"
95+
>
96+
<div className="absolute inset-0 flex items-center justify-center">
97+
<h1 className="text-8xl text-white font-thin">Hello World!</h1>
98+
</div>
99+
</ParallaxBanner>
100+
);
101+
};
102+
```
103+
104+
<ParallaxBannerEmbedHeadline />

documentation/docs/examples/easing.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 2
2+
sidebar_position: 3
33
---
44

55
import { EasingDemo } from '/src/components/easing-demo';
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
import { ParallaxBanner } from 'react-scroll-parallax';
3+
4+
export const ParallaxBannerEmbedHeadline = () => {
5+
return (
6+
<ParallaxBanner
7+
layers={[
8+
{
9+
image:
10+
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/105988/banner-background.jpg',
11+
speed: -30,
12+
shouldAlwaysCompleteAnimation: true,
13+
},
14+
{
15+
speed: -12,
16+
children: (
17+
<div className="absolute inset-0 flex items-center justify-center">
18+
<h1 className="text-8xl text-white font-thin">Hello World!</h1>
19+
</div>
20+
),
21+
shouldAlwaysCompleteAnimation: true,
22+
},
23+
{
24+
image:
25+
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/105988/banner-foreground.png',
26+
speed: -10,
27+
shouldAlwaysCompleteAnimation: true,
28+
},
29+
]}
30+
className="h-48"
31+
/>
32+
);
33+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
import { ParallaxBanner } from 'react-scroll-parallax';
3+
4+
export const ParallaxBannerImages = () => {
5+
return (
6+
<ParallaxBanner
7+
layers={[
8+
{
9+
image:
10+
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/105988/banner-background.jpg',
11+
speed: -30,
12+
shouldAlwaysCompleteAnimation: true,
13+
},
14+
{
15+
image:
16+
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/105988/banner-foreground.png',
17+
speed: -10,
18+
shouldAlwaysCompleteAnimation: true,
19+
},
20+
]}
21+
className="h-48"
22+
/>
23+
);
24+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import { ParallaxBanner } from 'react-scroll-parallax';
3+
4+
export const ParallaxBannerWithHeadline = () => {
5+
return (
6+
<ParallaxBanner
7+
layers={[
8+
{
9+
image:
10+
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/105988/banner-background.jpg',
11+
speed: -30,
12+
shouldAlwaysCompleteAnimation: true,
13+
},
14+
{
15+
image:
16+
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/105988/banner-foreground.png',
17+
speed: -10,
18+
shouldAlwaysCompleteAnimation: true,
19+
},
20+
]}
21+
className="h-48"
22+
>
23+
<div className="absolute inset-0 flex items-center justify-center">
24+
<h1 className="text-8xl text-white font-thin">Hello World!</h1>
25+
</div>
26+
</ParallaxBanner>
27+
);
28+
};

0 commit comments

Comments
 (0)