Skip to content

Commit 78edd06

Browse files
mordechaimmordechai
authored andcommitted
1 parent 9b0cce2 commit 78edd06

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/lib/ScrollspyNav.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class ScrollspyNav extends Component {
1515
this.scrollDuration = Number(this.props.scrollDuration) || 1000;
1616
this.headerBackground = this.props.headerBackground === "true" ? true : false;
1717
this.offset = this.props.offset || 0;
18+
this.scrollDestination = 0;
1819

1920
this.onScroll = this.onScroll.bind(this);
2021

@@ -69,11 +70,20 @@ class ScrollspyNav extends Component {
6970
* @param {Number} duration
7071
*/
7172
scrollTo(start, to, duration) {
73+
this.scrollDestination = to;
7274
let change = to - start,
7375
currentTime = 0,
7476
increment = 10;
7577

7678
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+
7787
currentTime += increment;
7888
let val = this.easeInOutQuad(currentTime, start, change, duration);
7989
window.scrollTo(0, val);
@@ -140,6 +150,7 @@ class ScrollspyNav extends Component {
140150
});
141151
})
142152

153+
this.onScroll();
143154
window.addEventListener("scroll", this.onScroll);
144155
}
145156

0 commit comments

Comments
 (0)