Skip to content

Commit be3890e

Browse files
committed
add event callbacks
1 parent ba4bac9 commit be3890e

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

docs/parallax-component.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ The **_end_** of an effect begins when the element's original position exits the
8787
| **scaleZ** | `number[]` | Start and end scale on z-axis. |
8888
| **opacity** | `number[]` | Start and end opacity value. |
8989

90-
### Easing Presets
90+
#### Easing Presets
9191

9292
The following easing values are preset and can be used as easing
9393

@@ -126,10 +126,18 @@ easeOutBack
126126
easeInOutBack
127127
```
128128
129-
### Cubic Bezier Easing Function
129+
#### Cubic Bezier Easing Function
130130
131131
Just like with CSS `cubic-bezier(0.2,-0.67,1,-0.62);`, you can supply the 4 params to a custom bezier function.
132132
133133
```jsx
134134
<Parallax easing={[0.2, -0.6, 1, -0.6]} />
135135
```
136+
137+
### Props: Callbacks
138+
139+
| Name | Type | Description |
140+
| -------------------- | :--------: | --------------------------------------------------------------------- |
141+
| **onProgressChange** | `function` | Callback for when the progress of an element in the viewport changes. |
142+
| **onEnter** | `function` | Callback for when an element enters the viewport. |
143+
| **onExit** | `function` | Callback for when an element exits the viewport. |

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.22"
77+
"parallax-controller": "0.1.23"
7878
},
7979
"devDependencies": {
8080
"@babel/core": "^7.16.0",

src/components/Parallax/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export function Parallax(props: PropsWithChildren<ParallaxProps>) {
5252
opacity: props.opacity,
5353
easing: props.easing,
5454
rootMargin: props.rootMargin,
55+
onProgressChange: props.onProgressChange,
56+
onEnter: props.onEnter,
57+
onExit: props.onExit,
5558
}),
5659
};
5760
}
@@ -94,6 +97,9 @@ export function Parallax(props: PropsWithChildren<ParallaxProps>) {
9497
props.opacity,
9598
props.easing,
9699
props.rootMargin,
100+
props.onProgressChange,
101+
props.onEnter,
102+
props.onExit,
97103
]);
98104

99105
const Outer = props.tagOuter;

src/components/Parallax/types.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,17 @@ export interface ParallaxProps {
171171
* Optionally pass an element tag name to be applied to the outermost parallax element.
172172
*/
173173
tagOuter?: any;
174+
175+
/**
176+
* Callback for when the progress of an element in the viewport changes.
177+
*/
178+
onProgressChange?: (progress: number) => any;
179+
/**
180+
* Callback for when an element enters the viewport.
181+
*/
182+
onEnter?: () => any;
183+
/**
184+
* Callback for when an element exits the viewport.
185+
*/
186+
onExit?: () => any;
174187
}

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.22:
11282-
version "0.1.22"
11283-
resolved "https://registry.yarnpkg.com/parallax-controller/-/parallax-controller-0.1.22.tgz#775f2d2008dc01a7d2490a4ae4c4d1cb08b87365"
11284-
integrity sha512-wUYgVaT4A223Zr4HvXubVnnjK9tNQE9GVgOBB+QIPFEkorgDrhLCpb2sLqNpIcRGBO/YgQLEEKUBmznNVrDjTA==
11281+
parallax-controller@0.1.23:
11282+
version "0.1.23"
11283+
resolved "https://registry.yarnpkg.com/parallax-controller/-/parallax-controller-0.1.23.tgz#dcde479c69524e8ca373abc29ce3194b8ebeeb52"
11284+
integrity sha512-S85cR/WaCZyC2Iuac3a2q9Q1ljMW75OTSol3Ds9vvqnjCAf+Z2r/JAqIjGeDndO98LwSe0jDtLMcGSB29S5AJw==
1128511285
dependencies:
1128611286
bezier-easing "^2.1.0"
1128711287

0 commit comments

Comments
 (0)