Skip to content

Commit 0f9d43c

Browse files
committed
chore: vary effects on 100 element story
1 parent b2226f5 commit 0f9d43c

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

stories/Container.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
import { ScrollAxis } from 'parallax-controller';
12
import React from 'react';
3+
import { PropsWithChildren } from 'react';
24
import { ParallaxProvider } from '../src';
35

4-
export const Container = ({ children, scrollAxis, className }) => (
5-
<ParallaxProvider scrollAxis={scrollAxis}>
6-
<div className={scrollAxis}>
7-
<div className={className}>{children}</div>
6+
type ContainerProps = PropsWithChildren<{
7+
scrollAxis: ScrollAxis;
8+
className?: string;
9+
}>;
10+
11+
export const Container = (props: ContainerProps) => (
12+
<ParallaxProvider scrollAxis={props.scrollAxis}>
13+
<div className={props.scrollAxis}>
14+
<div className={props.className}>{props.children}</div>
815
</div>
916
</ParallaxProvider>
1017
);

stories/Parallax/1_ParallaxVertical.stories.tsx

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import styles from './Parallax.module.scss';
77
import { useRef } from 'react';
88
import { CSSEffect } from 'parallax-controller';
99
import { useState } from 'react';
10+
import { ParallaxProps } from '../../src/components/Parallax/types';
1011

1112
export const WithYOffsets = (args) => {
1213
const a = args.y1.split(',');
@@ -175,31 +176,38 @@ StartAnimationAtInitialPosition.args = {
175176
endTranslateX: -80,
176177
};
177178

179+
const propConfigs: ParallaxProps[] = [
180+
{
181+
translateY: [`100%`, `-100%`, 'easeInOutQuad'],
182+
translateX: [`100%`, `-100%`],
183+
},
184+
{ translateY: [`-100%`, `100%`], translateX: [`-100%`, `100%`] },
185+
{ scale: [0, 1], translateX: [`-100%`, `100%`] },
186+
{ scale: [1, 0, 'easeInCubic'], translateY: [`-100%`, `100%`] },
187+
{ rotate: [0, 360], scale: [1, 0, 'easeInOutBack'] },
188+
{ rotate: [0, -360, 'easeInExpo'], scale: [0, 1] },
189+
{ translateY: [`-100%`, `100%`], rotateY: [0, 360] },
190+
{
191+
translateX: [`-100%`, `100%`, 'easeInCubic'],
192+
opacity: [0, 1, 'easeInCubic'],
193+
},
194+
];
195+
178196
export const WithAHundredElements = () => {
179197
const amount = 100;
180-
const offset = 50;
181198
const elements = new Array(amount).fill(null).map((x, i) => i);
182199

183200
return (
184201
<Container scrollAxis="vertical">
185202
<div className={styles.elements}>
186203
{elements.map((_, i) => {
187-
const even = i % 2 === 0;
188-
const props = {
189-
translateX: [
190-
even ? `${offset}%` : `${-offset}%`,
191-
even ? `${-offset}%` : `${offset}%`,
192-
],
193-
translateY: [
194-
even ? `${offset}%` : `${-offset}%`,
195-
even ? `${-offset}%` : `${offset}%`,
196-
],
197-
};
198-
204+
const props: ParallaxProps = propConfigs[i % propConfigs.length];
199205
return (
200-
<Parallax key={i} className={styles.small} {...props}>
201-
<Element name={i + 1} />
202-
</Parallax>
206+
<div key={i} className={styles.small} style={{ perspective: 800 }}>
207+
<Parallax {...props}>
208+
<Element name={i + 1} />
209+
</Parallax>
210+
</div>
203211
);
204212
})}
205213
</div>

stories/styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ body {
5656
.vertical {
5757
width: 100%;
5858
min-height: 300vh;
59-
overflow-x: hidden;
59+
overflow: hidden;
6060
}
6161
.vertical:before {
6262
content: '↑ Scroll ↓';

0 commit comments

Comments
 (0)