Skip to content

Commit f4a6e39

Browse files
committed
docs: add advanced banners doc
1 parent 9dde06e commit f4a6e39

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
hide_title: true
3+
title: Advanced Banners
4+
sidebar_position: 3
5+
---
6+
7+
import { AdvancedBannerTop } from '/src/components/advanced-banner-top';
8+
import { ParallaxBannerWithHeadline } from '/src/components/parallax-banner-with-headline';
9+
import { ParallaxBannerEmbedHeadline } from '/src/components/parallax-banner-embed-headline';
10+
11+
<AdvancedBannerTop />
12+
13+
# Advanced Banners
14+
15+
The `<ParallaxBanner>` accepts advanced configurations that can allow you to really push the effect. Building off the [previous banner demos](/docs/examples/banners), this one adds a number of configuration options.
16+
17+
## How it's done
18+
19+
The following is a breakdown of some of the more advanced configuration for the banner seen above.
20+
21+
1. You are not limited to using only `speed` to control movement. In this example `translateY` is defined with custom start and end values. This is helpful when the banner starts at the top of the page.
22+
2. Setting `shouldAlwaysCompleteAnimation` ensures that the animation begins at the initial position in the view, and since this banner is placed at the top of the page this option is enabled.
23+
3. Additional `scale` effects are used to further enhance the scenes depth and are also provided individual `easing` values.
24+
4. Certain layers set `expanded` to `false`. This is because they don't move or have no edge that would appear visible so there is no need to expand them.
25+
5. Lastly, a gradient overlay is added to dim the scene with an `opacity` transition.
26+
27+
```tsx
28+
const Component = () => {
29+
const background: BannerLayer = {
30+
image:
31+
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/105988/banner-background.jpg',
32+
translateY: [0, 50],
33+
opacity: [1, 0.3],
34+
scale: [1.05, 1, 'easeOutCubic'],
35+
shouldAlwaysCompleteAnimation: true,
36+
};
37+
38+
const headline: BannerLayer = {
39+
translateY: [0, 30],
40+
scale: [1, 1.05, 'easeOutCubic'],
41+
shouldAlwaysCompleteAnimation: true,
42+
expanded: false,
43+
children: (
44+
<div className="absolute inset-0 flex items-center justify-center">
45+
<h1 className="text-6xl md:text-8xl text-white font-thin">
46+
Hello World!
47+
</h1>
48+
</div>
49+
),
50+
};
51+
52+
const foreground: BannerLayer = {
53+
image:
54+
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/105988/banner-foreground.png',
55+
translateY: [0, 15],
56+
scale: [1, 1.1, 'easeOutCubic'],
57+
shouldAlwaysCompleteAnimation: true,
58+
};
59+
60+
const gradientOverlay: BannerLayer = {
61+
opacity: [0, 0.9],
62+
shouldAlwaysCompleteAnimation: true,
63+
expanded: false,
64+
children: (
65+
<div className="absolute inset-0 bg-gradient-to-t from-gray-900 to-blue-900" />
66+
),
67+
};
68+
69+
return (
70+
<ParallaxBanner
71+
layers={[background, headline, foreground, gradientOverlay]}
72+
className="aspect-[2/1] bg-gray-900"
73+
/>
74+
);
75+
};
76+
```
77+
78+
:::info
79+
80+
Each layer of the `<ParallaxBanner>` is just a `useParallax` hook targeting a `<div>`. Which means anything you can use to configure [`useParallax`](/docs/usage/hooks/use-parallax) can be used as a property of a `layer`. See all [effects and configuration](https://parallax-controller.v1.damnthat.tv/docs/usage/props) accepted.
81+
82+
:::

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: 3
2+
sidebar_position: 4
33
---
44

55
import { EasingDemo } from '/src/components/easing-demo';
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React from 'react';
2+
import { ParallaxBanner } from 'react-scroll-parallax';
3+
import { BannerLayer } from 'react-scroll-parallax/dist/components/ParallaxBanner/types';
4+
5+
export const AdvancedBannerTop = () => {
6+
const background: BannerLayer = {
7+
image:
8+
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/105988/banner-background.jpg',
9+
translateY: [0, 50],
10+
opacity: [1, 0.3],
11+
scale: [1.05, 1, 'easeOutCubic'],
12+
shouldAlwaysCompleteAnimation: true,
13+
};
14+
15+
const headline: BannerLayer = {
16+
translateY: [0, 30],
17+
scale: [1, 1.05, 'easeOutCubic'],
18+
shouldAlwaysCompleteAnimation: true,
19+
expanded: false,
20+
children: (
21+
<div className="absolute inset-0 flex items-center justify-center">
22+
<h1 className="text-6xl md:text-8xl text-white font-thin">
23+
Hello World!
24+
</h1>
25+
</div>
26+
),
27+
};
28+
29+
const foreground: BannerLayer = {
30+
image:
31+
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/105988/banner-foreground.png',
32+
translateY: [0, 15],
33+
scale: [1, 1.1, 'easeOutCubic'],
34+
shouldAlwaysCompleteAnimation: true,
35+
};
36+
37+
const gradientOverlay: BannerLayer = {
38+
opacity: [0, 0.9],
39+
shouldAlwaysCompleteAnimation: true,
40+
expanded: false,
41+
children: (
42+
<div className="absolute inset-0 bg-gradient-to-t from-gray-900 to-blue-900" />
43+
),
44+
};
45+
46+
return (
47+
<>
48+
<ParallaxBanner
49+
layers={[background, headline, foreground, gradientOverlay]}
50+
className="aspect-[2/1] bg-gray-900"
51+
/>
52+
<figcaption className="my-md">
53+
<p className="text-sm">Advanced banner configuration example.</p>
54+
</figcaption>
55+
</>
56+
);
57+
};

0 commit comments

Comments
 (0)