@@ -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 ] ) ;
163155ScrollLink . 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
179172ScrollLink . defaultProps = {
180173 component : 'div' ,
174+ offsetTop : 0 ,
181175 duration : 450 ,
182176 active : 'active' ,
183177 showHeightActive : '50%' ,
0 commit comments