|
| 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 /> |
0 commit comments