Skip to content

Commit 28dcf90

Browse files
committed
support onChange and targetElement
1 parent 86b43bd commit 28dcf90

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

src/components/Parallax/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ export function Parallax(props: PropsWithChildren<ParallaxProps>) {
5757
shouldStartAnimationInitialInView:
5858
props.shouldStartAnimationInitialInView,
5959
onProgressChange: props.onProgressChange,
60+
onChange: props.onChange,
6061
onEnter: props.onEnter,
6162
onExit: props.onExit,
6263
startScroll: props.startScroll,
6364
endScroll: props.endScroll,
65+
targetElement: props.targetElement,
6466
}),
6567
};
6668
}
@@ -108,8 +110,10 @@ export function Parallax(props: PropsWithChildren<ParallaxProps>) {
108110
props.easing,
109111
props.rootMargin,
110112
props.onProgressChange,
113+
props.onChange,
111114
props.onEnter,
112115
props.onExit,
116+
props.targetElement,
113117
]);
114118

115119
const Outer = props.tag;

stories/Parallax/1_ParallaxVertical.stories.tsx

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import { Parallax, ParallaxProvider } from '../../src';
33
import { Element } from '../Element/Element';
44
import { Container } from '../Container';
55
import { ScrollContainer } from '../ScrollContainer';
66
import styles from './Parallax.module.scss';
7+
import { useRef } from 'react';
8+
import { CSSEffect } from 'parallax-controller';
9+
import { useState } from 'react';
710

811
export const WithYOffsets = (args) => {
912
const a = args.y1.split(',');
@@ -262,6 +265,42 @@ WithDefinedStartEndScroll.args = {
262265
endScroll: 1000,
263266
};
264267

268+
export const WithDefinedTargetElement = () => {
269+
const a: CSSEffect = [0, 200];
270+
const b: CSSEffect = [0, -200];
271+
const targetRef = useRef();
272+
273+
const [targetElement, setElement] = useState();
274+
useEffect(() => {
275+
setElement(targetRef.current);
276+
}, []);
277+
278+
return (
279+
<Container scrollAxis="vertical" className={styles.elements}>
280+
<Parallax
281+
translateX={a}
282+
className="fixed top-0 left-0 w-32 h-32"
283+
targetElement={targetElement}
284+
>
285+
<Element name="1" />
286+
</Parallax>
287+
<Parallax
288+
translateX={b}
289+
className="fixed top-0 right-0 w-32 h-32"
290+
targetElement={targetElement}
291+
>
292+
<Element name="2" />
293+
</Parallax>
294+
<div
295+
className="w-screen h-screen bg-blue-500 bg-opacity-20 text-white flex items-center justify-center "
296+
ref={targetRef}
297+
>
298+
Target Element
299+
</div>
300+
</Container>
301+
);
302+
};
303+
265304
export default {
266305
title: 'Components / <Parallax> / Vertical Scroll',
267306
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.35:
11282-
version "0.1.35"
11283-
resolved "https://registry.yarnpkg.com/parallax-controller/-/parallax-controller-0.1.35.tgz#28ef2f57a30d3241123c65335ab5796ee95d87be"
11284-
integrity sha512-YCtjot8MiBPW3eZ1tbNga1jOPjJT3UsHx67FmCXMQugpZHGSlts0zgMy/hKvAqStuVq5TVv05Sg4o/bSyHn7Dg==
11281+
parallax-controller@^0.1.36:
11282+
version "0.1.36"
11283+
resolved "https://registry.yarnpkg.com/parallax-controller/-/parallax-controller-0.1.36.tgz#6dfe8448b40bfa6f1740a329a9a36c6fe6b88157"
11284+
integrity sha512-pWOh+fQtF405vDTHJPVzddMu5NdUUHYb6xbVok/X+tgUSIFs05QfRPZ6alMcx6iSG+9U/jk+xqTjmsee3q0Sxg==
1128511285
dependencies:
1128611286
bezier-easing "^2.1.0"
1128711287

0 commit comments

Comments
 (0)