Skip to content

Commit 39645a7

Browse files
committed
add support for rootMargin
1 parent 6b309fa commit 39645a7

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

docs/parallax-component.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,17 @@ The following are all props that can be passed to the `<Parallax>` component:
4545

4646
### Props: Configuration
4747

48-
| Name | Type | Default | Description |
49-
| -------------- | :--------------------: | :------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
50-
| **speed** | `number` | | A value representing the elements scroll speed. If less than zero scroll will appear slower. If greater than zero scroll will appear faster. |
51-
| **easing** | `string` or `number[]` | | String representing an [easing preset](#easing-presets) or array of params to supply to a [cubic bezier easing function](#cubic-bezier-easing-function). |
52-
| **className** | `string` | | Optionally pass additional class names to be added to the outermost parallax element. |
53-
| **disabled** | `boolean` | `false` | Disables parallax effects on individual elements when `true`. |
54-
| **styleInner** | `object` | | Optionally pass a style object to be added to the innermost parallax element. |
55-
| **styleOuter** | `object` | | Optionally pass a style object to be added to the outermost parallax element. |
56-
| **tagInner** | `string` | `div` | Optionally pass an element tag name to be applied to the innermost parallax element. |
57-
| **tagOuter** | `string` | `div` | Optionally pass an element tag name to be applied to the outermost parallax element. |
48+
| Name | Type | Default | Description |
49+
| -------------- | :--------------------: | :------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
50+
| **speed** | `number` | | A value representing the elements scroll speed. If less than zero scroll will appear slower. If greater than zero scroll will appear faster. |
51+
| **easing** | `string` or `number[]` | | String representing an [easing preset](#easing-presets) or array of params to supply to a [cubic bezier easing function](#cubic-bezier-easing-function). |
52+
| **rootMargin** | `object` | | Margin to be applied as the bounds around an element. This will affect when an element is determined to be considered in the viewport. Example: `{ top: 100, right: 100, bottom: 100, left: 100 }` |
53+
| **className** | `string` | | Optionally pass additional class names to be added to the outermost parallax element. |
54+
| **disabled** | `boolean` | `false` | Disables parallax effects on individual elements when `true`. |
55+
| **styleInner** | `object` | | Optionally pass a style object to be added to the innermost parallax element. |
56+
| **styleOuter** | `object` | | Optionally pass a style object to be added to the outermost parallax element. |
57+
| **tagInner** | `string` | `div` | Optionally pass an element tag name to be applied to the innermost parallax element. |
58+
| **tagOuter** | `string` | `div` | Optionally pass an element tag name to be applied to the outermost parallax element. |
5859

5960
### Props: CSS Effects
6061

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

src/components/Parallax/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export function Parallax(props: PropsWithChildren<ParallaxProps>) {
5151
scaleZ: props.scaleZ,
5252
opacity: props.opacity,
5353
easing: props.easing,
54+
rootMargin: props.rootMargin,
5455
}),
5556
};
5657
}
@@ -92,6 +93,7 @@ export function Parallax(props: PropsWithChildren<ParallaxProps>) {
9293
props.speed,
9394
props.opacity,
9495
props.easing,
96+
props.rootMargin,
9597
]);
9698

9799
const Outer = props.tagOuter;

src/components/Parallax/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ValidEasingPresets } from 'parallax-controller';
1+
import { RootMarginShape, ValidEasingPresets } from 'parallax-controller';
22

33
export interface ParallaxProps {
44
/**
@@ -140,6 +140,13 @@ export interface ParallaxProps {
140140
* Example params: [0.42, 0, 0.58, 1]
141141
*/
142142
easing?: number[] | ValidEasingPresets;
143+
/**
144+
* Margin to be applied as the bounds around an element.
145+
* This will affect when an element is determined to be considered in the viewport.
146+
*
147+
* Example: rootMargin={{ top: 100, right: 100, bottom: 100, left: 100 }}
148+
*/
149+
rootMargin?: RootMarginShape;
143150
/**
144151
* Optionally pass additional class names to be added to the outermost parallax element.
145152
*/

yarn.lock

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

11058-
parallax-controller@0.1.17:
11059-
version "0.1.17"
11060-
resolved "https://registry.yarnpkg.com/parallax-controller/-/parallax-controller-0.1.17.tgz#ef135fb4d4934dcdc132c27756deac3379997b2c"
11061-
integrity sha512-DwWFjmerd8YqMX0iSy2LeAQjF646hcDoFYiwCa+GOYJqmIhjLjKxy/dY2uRkXKm4oGKBde61CDRLwNfOq0KeFw==
11058+
parallax-controller@0.1.21:
11059+
version "0.1.21"
11060+
resolved "https://registry.yarnpkg.com/parallax-controller/-/parallax-controller-0.1.21.tgz#e8d4566ca2c01662621e895320d95a4134e48f9f"
11061+
integrity sha512-P9KhQe3xOJTo7SmeXtJO0J96pJPildNcLvcvvkswrFbIJYWB3qO8HT5V51C2/HitCHv5cdck01ot+AcI74hI4Q==
1106211062
dependencies:
1106311063
bezier-easing "^2.1.0"
1106411064

0 commit comments

Comments
 (0)