Skip to content

Commit c9c5ee2

Browse files
committed
use speed prop for parallax banner
1 parent d4102fb commit c9c5ee2

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

docs/parallax-banner-component.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Use the `layers` prop to indicate all images, offset amounts, and scroll rates.
1212
layers={[
1313
{
1414
image: 'https://foo.com/foo.jpg',
15-
amount: 0.1,
15+
speed: 0.1,
1616
},
1717
{
1818
image: 'https://foo.com/bar.png',
19-
amount: 0.2,
19+
speed: 0.2,
2020
},
2121
]}
2222
style={{
@@ -27,7 +27,7 @@ Use the `layers` prop to indicate all images, offset amounts, and scroll rates.
2727
</ParallaxBanner>
2828
```
2929

30-
## Banner Props
30+
## Props
3131

3232
The following are all props that can be passed to the `<ParallaxBanner>` component:
3333

@@ -44,7 +44,7 @@ The `layers` prop takes an array of objects that will represent each image (or c
4444

4545
| Name | Type | Default | Description |
4646
| ------------ | :------------: | :------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
47-
| **amount** | `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. |
47+
| **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. |
4848
| **children** | `ReactElement` | | Custom layer children provided as a React element, for example `<Video />` |
4949
| **expanded** | `boolean` | `true` | Indicate if the layer should be expanded with negative top/bottom margins so the edges will never be visible. |
5050
| **image** | `string` | | Image source that will be applied as a CSS background image on the layer. |

src/components/ParallaxBanner/index.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('Expect the <ParallaxBanner> component', () => {
1919
layers={[
2020
{
2121
image: 'https://foo.com/bar.jpg',
22-
amount: 0.2,
22+
speed: 2,
2323
},
2424
]}
2525
style={{
@@ -50,7 +50,7 @@ describe('Expect the <ParallaxBanner> component', () => {
5050
layers={[
5151
{
5252
children: <div>test</div>,
53-
amount: 0.2,
53+
speed: 2,
5454
},
5555
]}
5656
style={{
@@ -75,7 +75,7 @@ describe('Expect the <ParallaxBanner> component', () => {
7575
layers={[
7676
{
7777
children: <div>test</div>,
78-
amount: 0.2,
78+
speed: 2,
7979
expanded: false,
8080
},
8181
]}
@@ -125,7 +125,7 @@ describe('Expect the <ParallaxBanner> component', () => {
125125
layers={[
126126
{
127127
children: <Child />,
128-
amount: 0.2,
128+
speed: 2,
129129
},
130130
]}
131131
/>
@@ -143,7 +143,7 @@ describe('Expect the <ParallaxBanner> component', () => {
143143
<ParallaxBanner
144144
layers={[
145145
{
146-
amount: 0.2,
146+
speed: 2,
147147
props: {
148148
style: {
149149
backgroundColor: 'red',

src/components/ParallaxBanner/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const ParallaxBanner = ({
3232
{layers.map(
3333
(
3434
{
35-
amount,
35+
speed,
3636
children: layerChildren,
3737
expanded = true,
3838
image,
@@ -55,10 +55,11 @@ export const ParallaxBanner = ({
5555
// if this is an expanded layer overwrite the top/bottom styles with negative margins
5656
const expandedStyle = expanded
5757
? {
58-
top: Math.abs(amount) * 100 * -1 + '%',
59-
bottom: Math.abs(amount) * 100 * -1 + '%',
58+
top: Math.abs(speed) * 10 * -1 + 'px',
59+
bottom: Math.abs(speed) * 10 * -1 + 'px',
6060
}
6161
: {};
62+
6263
// optional image styles
6364
const imageStyle = image
6465
? {
@@ -71,7 +72,7 @@ export const ParallaxBanner = ({
7172
return (
7273
<Parallax
7374
key={`layer-${i}`}
74-
translateY={[amount * -1 * 100 + '%', amount * 100 + '%']}
75+
speed={speed}
7576
styleInner={absoluteStyle}
7677
styleOuter={absoluteStyle}
7778
disabled={disabled}

src/components/ParallaxBanner/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
export interface BannerLayer {
22
/**
3-
* A value from `-1` to `1` that represents the vertical offset to be applied to the current
4-
* layer, `0.1` would equal a `10%` offset on the top and bottom.
3+
* A value representing the elements scroll speed. If less than zero scroll will appear slower. If greater than zero scroll will appear faster.
54
*/
6-
amount: number;
5+
speed: number;
76
/**
87
* Custom layer children provided as a React element, for example `<Video />`
98
*/

stories/ParallaxBanner/4_ParallaxBanner.stories.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ storiesOf('Components / <ParallaxBanner>', module)
1515
{
1616
image:
1717
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/105988/banner.jpg',
18-
amount: 0.2,
18+
speed: -20,
1919
},
2020
]}
2121
/>
@@ -36,7 +36,7 @@ storiesOf('Components / <ParallaxBanner>', module)
3636
{
3737
image:
3838
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/105988/banner.jpg',
39-
amount: 0.2,
39+
speed: -20,
4040
},
4141
]}
4242
/>
@@ -54,7 +54,7 @@ storiesOf('Components / <ParallaxBanner>', module)
5454
{
5555
image:
5656
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/105988/banner.jpg',
57-
amount: 0.2,
57+
speed: -20,
5858
},
5959
]}
6060
>
@@ -71,12 +71,12 @@ storiesOf('Components / <ParallaxBanner>', module)
7171
{
7272
image:
7373
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/105988/banner-background.jpg',
74-
amount: 0.5,
74+
speed: -20,
7575
},
7676
{
7777
image:
7878
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/105988/banner-foreground.png',
79-
amount: 0.25,
79+
speed: -10,
8080
},
8181
];
8282
return (
@@ -101,7 +101,7 @@ storiesOf('Components / <ParallaxBanner>', module)
101101
className={styles.bannerBg}
102102
layers={[
103103
{
104-
amount: 0.3,
104+
speed: -30,
105105
children: (
106106
<video
107107
className={styles.video}
@@ -138,7 +138,7 @@ storiesOf('Components / <ParallaxBanner>', module)
138138
Red
139139
</div>
140140
),
141-
amount: 0.2,
141+
speed: -10,
142142
expanded: false,
143143
},
144144
{
@@ -147,7 +147,7 @@ storiesOf('Components / <ParallaxBanner>', module)
147147
Green
148148
</div>
149149
),
150-
amount: 0.4,
150+
speed: -20,
151151
expanded: false,
152152
},
153153
{
@@ -156,7 +156,7 @@ storiesOf('Components / <ParallaxBanner>', module)
156156
Blue
157157
</div>
158158
),
159-
amount: 0.6,
159+
speed: -30,
160160
expanded: false,
161161
},
162162
]}
@@ -176,7 +176,7 @@ storiesOf('Components / <ParallaxBanner>', module)
176176
{
177177
image:
178178
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/105988/banner.jpg',
179-
amount: 0.2,
179+
speed: -20,
180180
},
181181
]}
182182
>

0 commit comments

Comments
 (0)