Skip to content

Commit 3f18c78

Browse files
committed
correct count of elements in ParallaxTest
1 parent 769efd8 commit 3f18c78

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

examples/parallax-test/components/ParallaxTest/ParallaxTest.js

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,28 @@ import { Parallax } from 'react-scroll-parallax';
33
import style from './ParallaxTest.scss';
44

55
const INC_AMOUNT = 10;
6+
const START_NUM_ELEMENTS = 10;
67

78
export default class ParallaxTest extends React.Component {
89

910
state = {
10-
amount: new Array(10).fill(null).map((x, i) => i),
11+
elements: new Array(START_NUM_ELEMENTS).fill(null).map((x, i) => i),
1112
offsetY: INC_AMOUNT,
1213
slowerScrollRate: false,
1314
unitPercent: false,
1415
};
1516

16-
mapToParallax() {
17-
const offsetY = this.state.offsetY;
18-
const slowerScrollRate = this.state.slowerScrollRate;
19-
20-
return this.state.amount.map((number, i) => {
21-
const unit = this.state.unitPercent ? '%' : 'px';
22-
const offsetYMin = offsetY * -1 * i + unit;
23-
const offsetYMax = offsetY * i + unit;
24-
25-
return (
26-
<Parallax
27-
key={i}
28-
tag="span"
29-
disabled={false}
30-
offsetYMax={offsetYMax}
31-
offsetYMin={offsetYMin}
32-
offsetXMax={0}
33-
offsetXMin={0}
34-
className={style.item}
35-
slowerScrollRate={slowerScrollRate}
36-
>
37-
{number}
38-
</Parallax>
39-
);
40-
});
41-
}
42-
4317
handleAdd = () => {
44-
const amount = [...this.state.amount, this.state.amount.length + 1];
18+
const elements = [...this.state.elements, this.state.elements.length];
4519
this.setState({
46-
amount,
20+
elements,
4721
});
4822
};
4923

5024
handleRemove = () => {
51-
const amount = this.state.amount.slice(0, this.state.amount.length - 1);
25+
const elements = this.state.elements.slice(0, this.state.elements.length - 1);
5226
this.setState({
53-
amount,
27+
elements,
5428
});
5529
};
5630

@@ -82,6 +56,33 @@ export default class ParallaxTest extends React.Component {
8256
});
8357
};
8458

59+
mapToParallax() {
60+
const offsetY = this.state.offsetY;
61+
const slowerScrollRate = this.state.slowerScrollRate;
62+
63+
return this.state.elements.map((number, i) => {
64+
const unit = this.state.unitPercent ? '%' : 'px';
65+
const offsetYMin = offsetY * -1 * i + unit;
66+
const offsetYMax = offsetY * i + unit;
67+
68+
return (
69+
<Parallax
70+
key={i}
71+
tag="span"
72+
disabled={false}
73+
offsetYMax={offsetYMax}
74+
offsetYMin={offsetYMin}
75+
offsetXMax={0}
76+
offsetXMin={0}
77+
className={style.item}
78+
slowerScrollRate={slowerScrollRate}
79+
>
80+
{number}
81+
</Parallax>
82+
);
83+
});
84+
}
85+
8586
render() {
8687
return (
8788
<div className={style.parallaxTest}>
@@ -92,7 +93,7 @@ export default class ParallaxTest extends React.Component {
9293
<div className={style.currentState}>
9394
<h4>
9495
Parallax Elements:
95-
<span className="value">{this.state.amount.length}</span>
96+
<span className="value">{this.state.elements.length}</span>
9697
</h4>
9798
<button onClick={this.handleAdd}>Add</button>
9899
<button onClick={this.handleRemove}>Remove</button>
@@ -123,4 +124,4 @@ export default class ParallaxTest extends React.Component {
123124
</div>
124125
);
125126
}
126-
}
127+
}

0 commit comments

Comments
 (0)