File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ class ScrollspyNav extends Component {
15
15
this . scrollDuration = Number ( this . props . scrollDuration ) || 1000 ;
16
16
this . headerBackground = this . props . headerBackground === "true" ? true : false ;
17
17
this . offset = this . props . offset || 0 ;
18
+ this . scrollDestination = 0 ;
18
19
19
20
this . onScroll = this . onScroll . bind ( this ) ;
20
21
@@ -69,11 +70,20 @@ class ScrollspyNav extends Component {
69
70
* @param {Number } duration
70
71
*/
71
72
scrollTo ( start , to , duration ) {
73
+ this . scrollDestination = to ;
72
74
let change = to - start ,
73
75
currentTime = 0 ,
74
76
increment = 10 ;
75
77
76
78
let animateScroll = ( ) => {
79
+ /*
80
+ * Stop previous animation when destination changes
81
+ *
82
+ * https://github.com/StephenWeiXu/react-scrollspy-nav/issues/28
83
+ */
84
+ if ( this . scrollDestination !== to )
85
+ return ;
86
+
77
87
currentTime += increment ;
78
88
let val = this . easeInOutQuad ( currentTime , start , change , duration ) ;
79
89
window . scrollTo ( 0 , val ) ;
@@ -140,6 +150,7 @@ class ScrollspyNav extends Component {
140
150
} ) ;
141
151
} )
142
152
153
+ this . onScroll ( ) ;
143
154
window . addEventListener ( "scroll" , this . onScroll ) ;
144
155
}
145
156
You can’t perform that action at this time.
0 commit comments