Skip to content

Commit 0f99304

Browse files
authored
Merge pull request #6 from Brudhu/master
Add offset prop to fix scrolling behavior
2 parents d0babf3 + 8b3a88e commit 0f99304

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ScrollspyNav extends Component {
99
this.activeNavClass = this.props.activeNavClass;
1010
this.scrollDuration = Number(this.props.scrollDuration) || 1000;
1111
this.headerBackground = this.props.headerBackground === "true" ? true : false;
12+
this.offset = this.props.offset;
1213

1314
if(this.props.router && this.props.router === "HashRouter") {
1415
this.homeDefaultLink = "#/";
@@ -30,8 +31,8 @@ class ScrollspyNav extends Component {
3031
let change = to - start,
3132
currentTime = 0,
3233
increment = 10;
33-
34-
let animateScroll = () => {
34+
35+
let animateScroll = () => {
3536
currentTime += increment;
3637
let val = this.easeInOutQuad(currentTime, start, change, duration);
3738
window.scrollTo(0, val);
@@ -67,7 +68,7 @@ class ScrollspyNav extends Component {
6768

6869
if(sectionID) {
6970
let scrollTargetPosition = document.getElementById(sectionID).offsetTop - (this.headerBackground ? document.querySelector("div[data-nav='list']").scrollHeight : 0);
70-
this.scrollTo(window.pageYOffset, scrollTargetPosition, this.scrollDuration);
71+
this.scrollTo(window.pageYOffset, scrollTargetPosition + this.offset, this.scrollDuration);
7172
} else {
7273
this.scrollTo(window.pageYOffset, 0, this.scrollDuration);
7374
}

0 commit comments

Comments
 (0)