Skip to content

Commit 28bc192

Browse files
committed
bump 0.4.0
1 parent c25c183 commit 28bc192

File tree

5 files changed

+22
-37
lines changed

5 files changed

+22
-37
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ ScrollAnim.scrollScreen.unMount();
161161
| active | string | `active`| selected className |
162162
| showHeightActive| string / number / array | `50%` | enter distance window top `50%` add `active`, leave same; is array [enter, leave]; |
163163
| toShowHeight | boolean | false | scroll to `showHeightActive` |
164+
| offsetTop | number | 0 | scroll to elem top offset |
164165
| onFocus | func | null | check callback,onFocus({target,to}) |
165166
| onBlur | func | null | blur callback |
166167
| component | string | `div` | - |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-scroll-anim",
3-
"version": "0.3.9",
3+
"version": "0.4.0",
44
"description": "scroll-anim anim component for react",
55
"keywords": [
66
"react",

src/ScrollLink.jsx

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ class ScrollLink extends React.Component {
2020
this.state = {
2121
active: false,
2222
};
23-
[
24-
'scrollEventListener',
25-
'onClick',
26-
'raf',
27-
].forEach((method) => this[method] = this[method].bind(this));
2823
}
2924

3025
componentDidMount() {
@@ -44,20 +39,20 @@ class ScrollLink extends React.Component {
4439
this.cancelRequestAnimationFrame();
4540
}
4641

47-
onClick(e) {
42+
onClick = (e) => {
4843
e.preventDefault();
4944
const docRect = document.documentElement.getBoundingClientRect();
5045
const elementDom = mapped.get(this.props.location);
5146
const elementRect = elementDom.getBoundingClientRect();
5247
this.scrollTop = currentScrollTop();
53-
const toTop = Math.round(elementRect.top) - Math.round(docRect.top) + Math.round(this.props.offset?this.props.offset:0);
48+
const toTop = Math.round(elementRect.top) - Math.round(docRect.top) + this.props.offsetTop;
5449
this.toTop = this.props.toShowHeight ?
5550
toTop - transformArguments(this.props.showHeightActive)[0] : toTop;
5651
this.initTime = Date.now();
5752
this.rafID = requestAnimationFrame(this.raf);
5853
}
5954

60-
raf() {
55+
raf = () => {
6156
if (this.rafID === -1) {
6257
return;
6358
}
@@ -74,12 +69,12 @@ class ScrollLink extends React.Component {
7469
}
7570
}
7671

77-
cancelRequestAnimationFrame() {
72+
cancelRequestAnimationFrame = () => {
7873
requestAnimationFrame.cancel(this.rafID);
7974
this.rafID = -1;
8075
}
8176

82-
scrollEventListener() {
77+
scrollEventListener = () => {
8378
const docRect = document.documentElement.getBoundingClientRect();
8479
const clientHeight = window.innerHeight ||
8580
document.documentElement.clientHeight || document.body.clientHeight;
@@ -147,6 +142,7 @@ class ScrollLink extends React.Component {
147142
'showHeightActive',
148143
'ease',
149144
'toShowHeight',
145+
'offsetTop',
150146
].forEach(key => delete props[key]);
151147
const reg = new RegExp(active, 'ig');
152148
const className = props.className || '';
@@ -156,19 +152,16 @@ class ScrollLink extends React.Component {
156152
}
157153
}
158154

159-
const stringOrNumber = React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.number]);
160-
const stringOrNumberOrArray = React.PropTypes.oneOfType([stringOrNumber, React.PropTypes.array]);
161-
const objectOrArray = React.PropTypes.oneOfType([React.PropTypes.object, React.PropTypes.array]);
162-
const childPropTypes = React.PropTypes.oneOfType([objectOrArray, React.PropTypes.string]);
163155
ScrollLink.propTypes = {
164156
component: React.PropTypes.string,
165-
children: childPropTypes,
157+
children: React.PropTypes.any,
166158
className: React.PropTypes.string,
167-
style: objectOrArray,
159+
style: React.PropTypes.any,
160+
offsetTop: React.PropTypes.number,
168161
duration: React.PropTypes.number,
169162
active: React.PropTypes.string,
170163
location: React.PropTypes.string,
171-
showHeightActive: stringOrNumberOrArray,
164+
showHeightActive: React.PropTypes.any,
172165
toShowHeight: React.PropTypes.bool,
173166
ease: React.PropTypes.string,
174167
onClick: React.PropTypes.func,
@@ -178,6 +171,7 @@ ScrollLink.propTypes = {
178171

179172
ScrollLink.defaultProps = {
180173
component: 'div',
174+
offsetTop: 0,
181175
duration: 450,
182176
active: 'active',
183177
showHeightActive: '50%',

src/ScrollOverPack.jsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ class ScrollOverPack extends React.Component {
2424
show: false,
2525
children: toArrayChildren(this.props.children),
2626
};
27-
[
28-
'scrollEventListener',
29-
].forEach((method) => this[method] = this[method].bind(this));
3027
}
3128

3229
componentDidMount() {
@@ -53,7 +50,7 @@ class ScrollOverPack extends React.Component {
5350
EventListener.removeEventListener(this.eventType, this.scrollEventListener);
5451
}
5552

56-
scrollEventListener(e) {
53+
scrollEventListener = (e) => {
5754
const clientHeight = window.innerHeight ||
5855
document.documentElement.clientHeight || document.body.clientHeight;
5956
const scrollTop = currentScrollTop();
@@ -136,16 +133,14 @@ class ScrollOverPack extends React.Component {
136133
return childToRender;
137134
}
138135
}
139-
const objectOrArray = React.PropTypes.oneOfType([React.PropTypes.object, React.PropTypes.array]);
140-
const numberOrArray = React.PropTypes.oneOfType([React.PropTypes.number, React.PropTypes.array]);
141136
ScrollOverPack.propTypes = {
142137
component: React.PropTypes.string,
143-
playScale: numberOrArray,
138+
playScale: React.PropTypes.any,
144139
always: React.PropTypes.bool,
145140
scrollEvent: React.PropTypes.func,
146-
children: objectOrArray,
141+
children: React.PropTypes.any,
147142
className: React.PropTypes.string,
148-
style: objectOrArray,
143+
style: React.PropTypes.any,
149144
scrollName: React.PropTypes.string,
150145
replay: React.PropTypes.bool,
151146
onChange: React.PropTypes.func,

src/ScrollParallax.jsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ class ScrollParallax extends React.Component {
3131
this.defaultTweenData = [];
3232
this.defaultData = [];
3333
this.state = {};
34-
[
35-
'scrollEventListener',
36-
].forEach((method) => this[method] = this[method].bind(this));
3734
}
3835

3936
componentDidMount() {
@@ -71,7 +68,7 @@ class ScrollParallax extends React.Component {
7168
EventListener.removeEventListener(this.eventType, this.scrollEventListener);
7269
}
7370

74-
setDefaultData(_vars) {
71+
setDefaultData = _vars => {
7572
const vars = dataToArray(_vars);
7673
const varsForIn = (item, i) => {
7774
const playScale = playScaleToArray(item.playScale).map(data => data * this.clientHeight);
@@ -93,7 +90,7 @@ class ScrollParallax extends React.Component {
9390
vars.forEach(varsForIn);
9491
}
9592

96-
scrollEventListener() {
93+
scrollEventListener = () => {
9794
const scrollTop = currentScrollTop();
9895
this.clientHeight = window.innerHeight ||
9996
document.documentElement.clientHeight || document.body.clientHeight;
@@ -175,16 +172,14 @@ class ScrollParallax extends React.Component {
175172
}
176173
}
177174

178-
const objectOrArray = React.PropTypes.oneOfType([React.PropTypes.object, React.PropTypes.array]);
179-
const childPropTypes = React.PropTypes.oneOfType([objectOrArray, React.PropTypes.string]);
180175
ScrollParallax.propTypes = {
181176
component: React.PropTypes.string,
182-
animation: objectOrArray,
177+
animation: React.PropTypes.any,
183178
always: React.PropTypes.bool,
184179
location: React.PropTypes.string,
185-
children: childPropTypes,
180+
children: React.PropTypes.any,
186181
className: React.PropTypes.string,
187-
style: objectOrArray,
182+
style: React.PropTypes.any,
188183
scrollName: React.PropTypes.string,
189184
};
190185

0 commit comments

Comments
 (0)