Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "offset" option #17

Merged
merged 2 commits into from
May 17, 2018
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ const options = {
// Example: document.querySelector('#element-to-scroll'),
element: window,

// Additional offset value that gets added to the desiredOffset. This is
// useful when passing a DOM object as the desiredOffset and wanting to adjust
// for an fixed nav or to add some padding.
offset: 0,

// should animated scroll be canceled on user scroll/keypress
// if set to "false" user input will be disabled until animated scroll is complete
cancelOnUserAction: true,
Expand Down
6 changes: 5 additions & 1 deletion animated-scroll-to.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
element: window,
horizontal: false,
onComplete: undefined,
passive: true
passive: true,
offset: 0
};

var optionsKeys = Object.keys(options);
Expand Down Expand Up @@ -46,6 +47,9 @@
}
}

// Add additonal user offset
desiredOffset += options.offset

options.isWindow = options.element === window;

var initialScrollPosition = null;
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@
},
"homepage": "https://github.com/Stanko/animated-scroll-to#readme",
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1"
}
}
Loading