Skip to content

Commit 8efdf9d

Browse files
committed
docs: add easing demo
1 parent 66abf08 commit 8efdf9d

File tree

4 files changed

+85
-10
lines changed

4 files changed

+85
-10
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { EasingDemo } from '/src/components/easing-demo';
2+
3+
# Easing
4+
5+
You can provide [easing presets](https://parallax-controller.v1.damnthat.tv/docs/usage/props#cubic-bezier-easing-function) or [cubic-bezier curve params](https://parallax-controller.v1.damnthat.tv/docs/usage/props#cubic-bezier-easing-function) to the `useParallax` hook or `<Parallax />` component.
6+
7+
## Example using a preset
8+
9+
This `translateX` effect will be eased using the `easeOutQuad` preset.
10+
11+
```tsx
12+
function Component() {
13+
const parallax = useParallax<HTMLDivElement>({
14+
easing: 'easeOutQuad',
15+
translateX: [0, 100],
16+
});
17+
return <div ref={parallax.ref} />;
18+
}
19+
```
20+
21+
**Note:** When defining an `easing` prop like above, ALL provided CSS effects will be eased.
22+
23+
<EasingDemo easing="easeOutQuad" />
24+
25+
# Custom cubic-bezier
26+
27+
Define a custom cubic-bezier curve by providing the 4 params to the `easing` prop.
28+
29+
```tsx
30+
function Component() {
31+
const parallax = useParallax<HTMLDivElement>({
32+
easing: [1, -0.75, 0.5, 1.34],
33+
translateX: [0, 100],
34+
});
35+
return <div ref={parallax.ref} />;
36+
}
37+
```
38+
39+
<EasingDemo easing={[1, -0.75, 0.5, 1.34]} />

documentation/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"prism-react-renderer": "^1.2.1",
2323
"react": "^17.0.1",
2424
"react-dom": "^17.0.1",
25-
"react-scroll-parallax": "^3.0.0-beta.7"
25+
"react-scroll-parallax": "^3.0.0-beta.8"
2626
},
2727
"browserslist": {
2828
"production": [
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { EasingParam } from 'parallax-controller';
2+
import React from 'react';
3+
import { useParallax } from 'react-scroll-parallax';
4+
import { BgContainer } from '../bg-container';
5+
6+
export const EasingDemo = (props: { easing: EasingParam }) => {
7+
const parallaxLinear = useParallax<HTMLDivElement>({
8+
translateX: [0, 100],
9+
shouldStartAnimationInitialInView: true,
10+
});
11+
12+
const parallaxEased = useParallax<HTMLDivElement>({
13+
translateX: [0, 100],
14+
shouldStartAnimationInitialInView: true,
15+
easing: props.easing,
16+
});
17+
18+
return (
19+
<BgContainer>
20+
<div className="w-full pr-24">
21+
<div className="relative">
22+
<div ref={parallaxLinear.ref}>
23+
<div className="border-2 border-gray-200 border-solid flex items-center justify-center bg-gray-400 h-24 w-24 rounded-lg">
24+
<p className="text-center font-bold uppercase">Default</p>
25+
</div>
26+
</div>
27+
<div className="absolute inset-0" ref={parallaxEased.ref}>
28+
<div className="border-2 border-blue-200 border-solid flex items-center justify-center bg-blue-400 bg-opacity-90 h-24 w-24 rounded-lg">
29+
<p className="text-center font-bold uppercase">Eased!</p>
30+
</div>
31+
</div>
32+
</div>
33+
</div>
34+
</BgContainer>
35+
);
36+
};

documentation/yarn.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5402,10 +5402,10 @@ package-json@^6.3.0:
54025402
registry-url "^5.0.0"
54035403
semver "^6.2.0"
54045404

5405-
parallax-controller@^1.1.0:
5406-
version "1.1.0"
5407-
resolved "https://registry.yarnpkg.com/parallax-controller/-/parallax-controller-1.1.0.tgz#134114855d45665f73f3b366009846f8f446a105"
5408-
integrity sha512-7S9YrlIkIdFqigZpYVIjjRrGhSDBXa+tR++CL5tSjNotGSlJCn2148IeMy6+xIDi1zzjhnTY5ZJwQi/Ie9zYTg==
5405+
parallax-controller@^1.1.1:
5406+
version "1.1.1"
5407+
resolved "https://registry.yarnpkg.com/parallax-controller/-/parallax-controller-1.1.1.tgz#a83e9b1f74fd776e4ac548c7bc57296705dea2a4"
5408+
integrity sha512-wgC/af23fMD5LCK15A3VffXGiO3EXs+d1gs4pB3Hf4JZwZ6NXNC4dH6v4+ruCvxVA91C4znpyQ3OyiggEqG1HA==
54095409
dependencies:
54105410
bezier-easing "^2.1.0"
54115411

@@ -6179,12 +6179,12 @@ react-router@5.2.1, react-router@^5.2.0:
61796179
tiny-invariant "^1.0.2"
61806180
tiny-warning "^1.0.0"
61816181

6182-
react-scroll-parallax@^3.0.0-beta.7:
6183-
version "3.0.0-beta.7"
6184-
resolved "https://registry.yarnpkg.com/react-scroll-parallax/-/react-scroll-parallax-3.0.0-beta.7.tgz#d606d50f7fba757fb5cdb8c2a0dfb62207214ff0"
6185-
integrity sha512-cB5/+ZdGTnIwRKKTNYdma21uh5j0PQY1j2nknBWk1O8kxVBLkqToM7gkvSg9lfxB5UYpsZZoXRpAOAIqh5Jdyw==
6182+
react-scroll-parallax@^3.0.0-beta.8:
6183+
version "3.0.0-beta.8"
6184+
resolved "https://registry.yarnpkg.com/react-scroll-parallax/-/react-scroll-parallax-3.0.0-beta.8.tgz#9c4dbf5d103c2a22bc70a3db7934ee790d23dbde"
6185+
integrity sha512-9wNt39qjo86bpAWKfI7+FiFQPD9gJJooQzBRvEltCL5RPXOAHdllhjX3zdAzrPD5bCfsKVvPO2VD1REfCNkN7Q==
61866186
dependencies:
6187-
parallax-controller "^1.1.0"
6187+
parallax-controller "^1.1.1"
61886188

61896189
react-side-effect@^2.1.0:
61906190
version "2.1.1"

0 commit comments

Comments
 (0)