Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/lib/ScrollspyNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ScrollspyNav extends Component {
this.scrollDuration = Number(this.props.scrollDuration) || 1000;
this.headerBackground = this.props.headerBackground === "true" ? true : false;
this.offset = this.props.offset || 0;
this.scrollDestination = 0;

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

Expand Down Expand Up @@ -69,11 +70,20 @@ class ScrollspyNav extends Component {
* @param {Number} duration
*/
scrollTo(start, to, duration) {
this.scrollDestination = to;
let change = to - start,
currentTime = 0,
increment = 10;

let animateScroll = () => {
/*
* Stop previous animation when destination changes
*
* https://github.com/StephenWeiXu/react-scrollspy-nav/issues/28
*/
if (this.scrollDestination !== to)
return;

currentTime += increment;
let val = this.easeInOutQuad(currentTime, start, change, duration);
window.scrollTo(0, val);
Expand Down Expand Up @@ -140,6 +150,7 @@ class ScrollspyNav extends Component {
});
})

this.onScroll();
window.addEventListener("scroll", this.onScroll);
}

Expand Down