Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mordechaim authored and mordechai committed May 7, 2020
1 parent 9b0cce2 commit 78edd06
Showing 1 changed file with 11 additions and 0 deletions.
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

0 comments on commit 78edd06

Please sign in to comment.