Skip to content

Commit 0860c4d

Browse files
committed
support startScroll and endScroll props
1 parent add5149 commit 0860c4d

File tree

6 files changed

+51
-5
lines changed

6 files changed

+51
-5
lines changed

docs/parallax-component.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ The following are all props that can be passed to the `<Parallax>` component:
6464
| **tag** | `string` | `div` | HTML element tag name to be applied to the outermost parallax element. |
6565
| **innerTag** | `string` | `div` | HTML element tag name to be applied to the innermost parallax element. |
6666
| **shouldStartAnimationInitialInView** | `boolean` | `false` | Will start the animation at initial element position if the element is positioned inside the view when scroll is at zero. |
67+
| **startScroll** | `number` | | Scroll top value to begin the animation. When provided along with `endScroll` relative scroll values will be ignored. |
68+
| **endScroll** | `number` | | Scroll top value to end the animation. When provided along with `startScroll` relative scroll values will be ignored. |
6769

6870
### Props: CSS Effects
6971

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
}
7575
],
7676
"dependencies": {
77-
"parallax-controller": "^0.1.32"
77+
"parallax-controller": "^0.1.34"
7878
},
7979
"devDependencies": {
8080
"@babel/core": "^7.16.0",

src/components/Parallax/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export function Parallax(props: PropsWithChildren<ParallaxProps>) {
3535
}
3636

3737
return {
38+
// @ts-expect-error
3839
elInner: refInner.current,
40+
// @ts-expect-error
3941
elOuter: refOuter.current,
4042
props: removeUndefinedObjectKeys({
4143
disabled: props.disabled,
@@ -57,6 +59,8 @@ export function Parallax(props: PropsWithChildren<ParallaxProps>) {
5759
onProgressChange: props.onProgressChange,
5860
onEnter: props.onEnter,
5961
onExit: props.onExit,
62+
startScroll: props.startScroll,
63+
endScroll: props.endScroll,
6064
}),
6165
};
6266
}

src/components/Parallax/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,16 @@ export interface ParallaxProps {
180180
*/
181181
tag?: any;
182182

183+
/**
184+
* Scroll top value to begin the animation. When provided along with `endScroll` relative scroll values will be ignored.
185+
*/
186+
startScroll?: number;
187+
188+
/**
189+
* Scroll top value to end the animation. When provided along with `startScroll` relative scroll values will be ignored.
190+
*/
191+
endScroll?: number;
192+
183193
/**
184194
* Callback for when the progress of an element in the viewport changes.
185195
*/

stories/Parallax/1_ParallaxVertical.stories.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,36 @@ export const InsideADiv = () => {
232232
);
233233
};
234234

235+
export const WithDefinedStartEndScroll = (args) => {
236+
const a = [0, window.innerWidth / 2];
237+
const b = [0, -window.innerWidth / 2];
238+
return (
239+
<Container scrollAxis="vertical" className={styles.elements}>
240+
<Parallax
241+
translateX={a}
242+
startScroll={args.startScroll}
243+
endScroll={args.endScroll}
244+
className="fixed top-0 left-0 w-32 h-32"
245+
>
246+
<Element name="1" />
247+
</Parallax>
248+
<Parallax
249+
translateX={b}
250+
startScroll={args.startScroll}
251+
endScroll={args.endScroll}
252+
className="fixed top-0 right-0 w-32 h-32"
253+
>
254+
<Element name="2" />
255+
</Parallax>
256+
</Container>
257+
);
258+
};
259+
260+
WithDefinedStartEndScroll.args = {
261+
startScroll: 0,
262+
endScroll: 1000,
263+
};
264+
235265
export default {
236266
title: 'Components / <Parallax> / Vertical Scroll',
237267
component: WithYOffsets,

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11278,10 +11278,10 @@ pako@~1.0.5:
1127811278
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
1127911279
integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==
1128011280

11281-
parallax-controller@^0.1.31:
11282-
version "0.1.31"
11283-
resolved "https://registry.yarnpkg.com/parallax-controller/-/parallax-controller-0.1.31.tgz#74dd287f4ce7bc7da7f98dc43d7759443c584102"
11284-
integrity sha512-mIOuI5ZWMQnOWclxokN3GjHHzrOabfZUkx3RYMQsanYcTFMx7FRaAkzQTMkcuxaEJM0aoTzmNRXyfV8WBd324Q==
11281+
parallax-controller@^0.1.34:
11282+
version "0.1.34"
11283+
resolved "https://registry.yarnpkg.com/parallax-controller/-/parallax-controller-0.1.34.tgz#43384d4f3c7d86950f3790b00b1a30e57f15045e"
11284+
integrity sha512-Wzh4EO+5L8RmPfi1achJ6/72vJfBSFkjqde8pnlVuLhV3LwgW1FXXl0aDgA1+7+3GniJtI9iDUT2GRNoH+UDaQ==
1128511285
dependencies:
1128611286
bezier-easing "^2.1.0"
1128711287

0 commit comments

Comments
 (0)