|
| 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 | +::: |
0 commit comments